@jaaq/jaaq-sdk-js 1.2.1 → 1.3.0-dev-6e37d09-20261030

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 (44) hide show
  1. package/dist/embed/embed-collection.html +3 -2
  2. package/dist/embed/embed.html +3 -2
  3. package/dist/index.cjs +7 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.mjs +7 -1
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/jaaq-sdk.min.js +1 -1
  9. package/dist/jaaq-sdk.min.js.map +1 -1
  10. package/dist/ui/index.cjs +7 -1
  11. package/dist/ui/index.cjs.map +1 -1
  12. package/dist/ui/index.d.ts +1 -0
  13. package/dist/ui/index.mjs +7 -1
  14. package/dist/ui/index.mjs.map +1 -1
  15. package/dist/ui/jaaq-ui-bundled.min.js +2 -2
  16. package/dist/ui/jaaq-ui-bundled.min.js.map +1 -1
  17. package/dist/ui/jaaq-ui.min.js +1 -1
  18. package/dist/ui/jaaq-ui.min.js.map +1 -1
  19. package/dist/ui/react/index.cjs +7 -1
  20. package/dist/ui/react/index.cjs.map +1 -1
  21. package/dist/ui/react/index.d.ts +1 -0
  22. package/dist/ui/react/index.mjs +7 -1
  23. package/dist/ui/react/index.mjs.map +1 -1
  24. package/dist/ui/react/jaaq-ui-react.min.js +1 -1
  25. package/dist/ui/react/jaaq-ui-react.min.js.map +1 -1
  26. package/dist/ui/vanilla/index.cjs +7 -1
  27. package/dist/ui/vanilla/index.cjs.map +1 -1
  28. package/dist/ui/vanilla/index.d.ts +1 -0
  29. package/dist/ui/vanilla/index.mjs +7 -1
  30. package/dist/ui/vanilla/index.mjs.map +1 -1
  31. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js +2 -2
  32. package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js.map +1 -1
  33. package/dist/ui/vanilla/jaaq-vanilla.min.js +1 -1
  34. package/dist/ui/vanilla/jaaq-vanilla.min.js.map +1 -1
  35. package/dist/ui/webcomponents/index.cjs +7 -1
  36. package/dist/ui/webcomponents/index.cjs.map +1 -1
  37. package/dist/ui/webcomponents/index.d.ts +1 -0
  38. package/dist/ui/webcomponents/index.mjs +7 -1
  39. package/dist/ui/webcomponents/index.mjs.map +1 -1
  40. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js +2 -2
  41. package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js.map +1 -1
  42. package/dist/ui/webcomponents/jaaq-webcomponents.min.js +1 -1
  43. package/dist/ui/webcomponents/jaaq-webcomponents.min.js.map +1 -1
  44. package/package.json +23 -23
@@ -82,10 +82,11 @@
82
82
  <div class="error-container">
83
83
  <div class="error-content">
84
84
  <h1>⚠️ Collection Player Error</h1>
85
- <p>${message}</p>
85
+ <p></p>
86
86
  </div>
87
87
  </div>
88
88
  `;
89
+ container.querySelector('.error-content p').textContent = message;
89
90
  }
90
91
 
91
92
  function getQueryParams() {
@@ -326,7 +327,7 @@
326
327
  </script>
327
328
 
328
329
  <script
329
- src="https://cdn.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
330
+ src="https://cdn-dev.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
330
331
  onerror="
331
332
  console.error('[Embed Collection] Failed to load web component script');
332
333
  showError('Failed to load collection player script');
@@ -72,10 +72,11 @@
72
72
  <div class="error-container">
73
73
  <div class="error-content">
74
74
  <h1>⚠️ Player Error</h1>
75
- <p>${message}</p>
75
+ <p></p>
76
76
  </div>
77
77
  </div>
78
78
  `;
79
+ container.querySelector('.error-content p').textContent = message;
79
80
  }
80
81
 
81
82
  function getQueryParams() {
@@ -334,7 +335,7 @@
334
335
  </script>
335
336
 
336
337
  <script
337
- src="https://cdn.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
338
+ src="https://cdn-dev.jaaq.app/latest/jaaq-webcomponents-bundled.min.js"
338
339
  onerror="
339
340
  console.error('[Embed] Failed to load web component script');
340
341
  showError('Failed to load player script');
package/dist/index.cjs CHANGED
@@ -9,11 +9,17 @@ async function parseJson(res) {
9
9
  return undefined;
10
10
  return res.json();
11
11
  }
12
+ function trimTrailingSlashes(value) {
13
+ let end = value.length;
14
+ while (end > 0 && value[end - 1] === '/')
15
+ end--;
16
+ return value.slice(0, end);
17
+ }
12
18
  function joinUrl(baseUrl, apiVersion, clientId, path) {
13
19
  // return path if it is an absolute URL
14
20
  if (/^https?:\/\//i.test(path))
15
21
  return path;
16
- const base = baseUrl.replace(/\/+$/, '');
22
+ const base = trimTrailingSlashes(baseUrl);
17
23
  const relative = path.replace(/^\/+/, '');
18
24
  return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
19
25
  }
@@ -1 +1 @@
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 ?? (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,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,UAAkB,EAAE,QAAgB,EAAE,IAAY,EAAA;;AAElF,IAAA,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;AAAE,QAAA,OAAO,IAAI;IAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACzC,OAAO,CAAA,EAAG,IAAI,CAAA,KAAA,EAAQ,UAAU,CAAA,cAAA,EAAiB,kBAAkB,CA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"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 trimTrailingSlashes(value: string): string {\n let end = value.length;\n while (end > 0 && value[end - 1] === '/') end--;\n return value.slice(0, end);\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 = trimTrailingSlashes(baseUrl);\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,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IACF;AAEA;;;;AAIG;AACH,IAAA,OAAO,QAAQ,CAA+B,IAAgB,EAAE,UAAkB,EAAA;AAChF,QAAA,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,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
@@ -97,6 +97,7 @@ type CollectionV2DTO = {
97
97
  id: string;
98
98
  name: string;
99
99
  description: string;
100
+ series?: string[];
100
101
  imageUrl: string;
101
102
  idleVideo: {
102
103
  id: string;
package/dist/index.mjs CHANGED
@@ -7,11 +7,17 @@ async function parseJson(res) {
7
7
  return undefined;
8
8
  return res.json();
9
9
  }
10
+ function trimTrailingSlashes(value) {
11
+ let end = value.length;
12
+ while (end > 0 && value[end - 1] === '/')
13
+ end--;
14
+ return value.slice(0, end);
15
+ }
10
16
  function joinUrl(baseUrl, apiVersion, clientId, path) {
11
17
  // return path if it is an absolute URL
12
18
  if (/^https?:\/\//i.test(path))
13
19
  return path;
14
- const base = baseUrl.replace(/\/+$/, '');
20
+ const base = trimTrailingSlashes(baseUrl);
15
21
  const relative = path.replace(/^\/+/, '');
16
22
  return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
17
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","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 ?? (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,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,UAAkB,EAAE,QAAgB,EAAE,IAAY,EAAA;;AAElF,IAAA,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;AAAE,QAAA,OAAO,IAAI;IAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IACzC,OAAO,CAAA,EAAG,IAAI,CAAA,KAAA,EAAQ,UAAU,CAAA,cAAA,EAAiB,kBAAkB,CAAC,QAAQ,CAAC,CAAA,EAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAA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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 trimTrailingSlashes(value: string): string {\n let end = value.length;\n while (end > 0 && value[end - 1] === '/') end--;\n return value.slice(0, end);\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 = trimTrailingSlashes(baseUrl);\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,MAA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B,EAAA;AAChF,QAAA,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,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;;"}
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JaaqSDK={})}(this,function(t){"use strict";function e(t){const{baseUrl:e,apiKey:n,clientId:o,fetch:i,apiVersion:c}=t,s=i??globalThis.fetch;if(!s)throw new Error("No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.");const r={"Content-Type":"application/json","x-api-key":n},a=t=>function(t,e,n,o){if(/^https?:\/\//i.test(o))return o;const i=t.replace(/\/+$/,""),c=o.replace(/^\/+/,"");return`${i}/b2b/${e}/subscription/${encodeURIComponent(n)}${c.startsWith("/")?c:`/${c}`}`}(e,function(t){const e=t.toLowerCase();return"v1"===e||"v2"===e?e:"v1"}(c),o,t),l=async(t,e,n,o)=>{const i={method:t,headers:{...r,...n?.headers},...n};void 0!==o&&(i.body=JSON.stringify(o));return async function(t){if(!t.ok){const e=await t.text().catch(()=>"");throw new Error(`HTTP ${t.status}: ${e||t.statusText}`)}if(204!==t.status)return t.json()}(await s(a(e),i))};return{get:(t,e)=>l("GET",t,e),post:(t,e,n)=>l("POST",t,n,e),put:(t,e,n)=>l("PUT",t,n,e),patch:(t,e,n)=>l("PATCH",t,n,e),delete:(t,e)=>l("DELETE",t,e)}}const n="https://api.jaaq.app";class o{constructor(t,e){"v2"===e?(this.videos=function(t){return{async getById(e){const n=`/videos/${encodeURIComponent(e)}`;return(await t.get(n)).video}}}(t),this.collections=function(t){return{list:async()=>(await t.get("/collections")).collections,async getById(e){const n=`/collections/${encodeURIComponent(e)}`;return(await t.get(n)).collection}}}(t)):(this.videos=function(t){return{async getById(e){const n=`/videos/${encodeURIComponent(e)}`;return(await t.get(n)).video}}}(t),this.collections=function(t){return{list:async()=>(await t.get("/collections")).collections,async getById(e){const n=`/collections/${encodeURIComponent(e)}`;return(await t.get(n)).collection}}}(t))}static fromHttp(t,e){return new o(t,e)}static init(t){return c(t)}}function i(t){return c(t)}function c(t){const{baseUrl:i=n,apiKey:c,clientId:s,fetch:r,apiVersion:a="v1"}=t,l=e({baseUrl:i,apiKey:c,clientId:s,fetch:r??globalThis.fetch,apiVersion:a});return o.fromHttp(l,a)}t.BASE_URL=n,t.JaaqClient=o,t.createJaaqClient=i,t.createJaaqClientV1=function(t){return i({...t,apiVersion:"v1"})},t.createJaaqClientV2=function(t){return i({...t,apiVersion:"v2"})}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JaaqSDK={})}(this,function(t){"use strict";function e(t){const{baseUrl:e,apiKey:n,clientId:o,fetch:i,apiVersion:c}=t,s=i??globalThis.fetch;if(!s)throw new Error("No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.");const r={"Content-Type":"application/json","x-api-key":n},a=t=>function(t,e,n,o){if(/^https?:\/\//i.test(o))return o;const i=function(t){let e=t.length;for(;e>0&&"/"===t[e-1];)e--;return t.slice(0,e)}(t),c=o.replace(/^\/+/,"");return`${i}/b2b/${e}/subscription/${encodeURIComponent(n)}${c.startsWith("/")?c:`/${c}`}`}(e,function(t){const e=t.toLowerCase();return"v1"===e||"v2"===e?e:"v1"}(c),o,t),l=async(t,e,n,o)=>{const i={method:t,headers:{...r,...n?.headers},...n};void 0!==o&&(i.body=JSON.stringify(o));return async function(t){if(!t.ok){const e=await t.text().catch(()=>"");throw new Error(`HTTP ${t.status}: ${e||t.statusText}`)}if(204!==t.status)return t.json()}(await s(a(e),i))};return{get:(t,e)=>l("GET",t,e),post:(t,e,n)=>l("POST",t,n,e),put:(t,e,n)=>l("PUT",t,n,e),patch:(t,e,n)=>l("PATCH",t,n,e),delete:(t,e)=>l("DELETE",t,e)}}const n="https://api.jaaq.app";class o{constructor(t,e){"v2"===e?(this.videos=function(t){return{async getById(e){const n=`/videos/${encodeURIComponent(e)}`;return(await t.get(n)).video}}}(t),this.collections=function(t){return{list:async()=>(await t.get("/collections")).collections,async getById(e){const n=`/collections/${encodeURIComponent(e)}`;return(await t.get(n)).collection}}}(t)):(this.videos=function(t){return{async getById(e){const n=`/videos/${encodeURIComponent(e)}`;return(await t.get(n)).video}}}(t),this.collections=function(t){return{list:async()=>(await t.get("/collections")).collections,async getById(e){const n=`/collections/${encodeURIComponent(e)}`;return(await t.get(n)).collection}}}(t))}static fromHttp(t,e){return new o(t,e)}static init(t){return c(t)}}function i(t){return c(t)}function c(t){const{baseUrl:i=n,apiKey:c,clientId:s,fetch:r,apiVersion:a="v1"}=t,l=e({baseUrl:i,apiKey:c,clientId:s,fetch:r??globalThis.fetch,apiVersion:a});return o.fromHttp(l,a)}t.BASE_URL=n,t.JaaqClient=o,t.createJaaqClient=i,t.createJaaqClientV1=function(t){return i({...t,apiVersion:"v1"})},t.createJaaqClientV2=function(t){return i({...t,apiVersion:"v2"})}});
2
2
  //# sourceMappingURL=jaaq-sdk.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"jaaq-sdk.min.js","sources":["../src/core/httpClient.ts","../src/index.ts","../src/resources/v2/videos.ts","../src/resources/v2/collections.ts","../src/resources/v1/videos.ts","../src/resources/v1/collections.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 { 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","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 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"],"names":["createHttpClient","config","baseUrl","apiKey","clientId","fetch","fetchImpl","apiVersion","f","globalThis","Error","baseHeaders","fullUrl","path","test","base","replace","relative","encodeURIComponent","startsWith","joinUrl","version","v","toLowerCase","convertToValidAPIVersion","request","async","method","init","body","reqInit","headers","undefined","JSON","stringify","res","ok","text","catch","status","statusText","json","parseJson","get","post","put","patch","delete","BASE_URL","JaaqClient","constructor","http","this","videos","getById","id","video","createVideosResourceV2","collections","collection","createCollectionsResourceV2","createVideosResource","createCollectionsResource","fromHttp","buildClient","createJaaqClient"],"mappings":"8OA4CM,SAAUA,EAAiBC,GAC/B,MAAMC,QAAEA,EAAOC,OAAEA,EAAMC,SAAEA,EAAUC,MAAOC,EAASC,WAAEA,GAAeN,EAE9DO,EAA2BF,GAAcG,WAAWJ,MAC1D,IAAKG,EACH,MAAM,IAAIE,MAAM,kGAGlB,MAAMC,EAAsC,CAC1C,eAAgB,mBAChB,YAAaR,GAGTS,EAAWC,GA3BnB,SAAiBX,EAAiBK,EAAoBH,EAAkBS,GAEtE,GAAI,gBAAgBC,KAAKD,GAAO,OAAOA,EACvC,MAAME,EAAOb,EAAQc,QAAQ,OAAQ,IAC/BC,EAAWJ,EAAKG,QAAQ,OAAQ,IACtC,MAAO,GAAGD,SAAYR,kBAA2BW,mBAAmBd,KAAYa,EAASE,WAAW,KAAOF,EAAW,IAAIA,KAC5H,CAqBoCG,CAAQlB,EAnB5C,SAAkCmB,GAChC,MAAMC,EAAID,EAAQE,cAClB,MAAU,OAAND,GAAoB,OAANA,EAAmBA,EAC9B,IACT,CAeqDE,CAAyBjB,GAAaH,EA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,UAClB,EAEJ,CFyByBC,CAA4BT,KAE/CC,KAAKC,OGzCL,SAA+BF,GACnC,MAAO,CACL,aAAMG,CAAQC,GACZ,MAAM1C,EAAO,WAAWK,mBAAmBqC,KAE3C,aADuBJ,EAAKR,IAAyB9B,IACrC2C,KAClB,EAEJ,CHiCoBK,CAAqBV,GACnCC,KAAKM,YIzCL,SAAoCP,GACxC,MAAO,CACLzB,KAAU,gBAEeyB,EAAKR,IADf,iBAEGe,YAElB,aAAMJ,CAAQC,GACZ,MAAM1C,EAAO,gBAAgBK,mBAAmBqC,KAEhD,aADuBJ,EAAKR,IAAmC9B,IAC/C8C,UAClB,EAEJ,CJ4ByBG,CAA0BX,GAEjD,CAOA,eAAOY,CAAuCZ,EAAkB5C,GAC9D,OAAO,IAAI0C,EAAWE,EAAM5C,EAC9B,CAMA,WAAOqB,CAAmC3B,GACxC,OAAO+D,EAAY/D,EACrB,EAOI,SAAUgE,EAA+ChE,GAC7D,OAAO+D,EAAY/D,EACrB,CAeA,SAAS+D,EAA0C/D,GACjD,MAAMC,QAAEA,EAAU8C,EAAQ7C,OAAEA,EAAMC,SAAEA,EAAUC,MAAOC,EAASC,WAAEA,EAAa,MAASN,EAEhFkD,EAAOnD,EAAiB,CAC5BE,UACAC,SACAC,WACAC,MAAOC,GAAcG,WAAWJ,MAChCE,eAGF,OAAO0C,EAAWc,SAASZ,EAAM5C,EACnC,uEAzBM,SAA6BN,GACjC,OAAOgE,EAAiB,IAAKhE,EAAQM,WAAY,MACnD,uBAEM,SAA6BN,GACjC,OAAOgE,EAAiB,IAAKhE,EAAQM,WAAY,MACnD"}
1
+ {"version":3,"file":"jaaq-sdk.min.js","sources":["../src/core/httpClient.ts","../src/index.ts","../src/resources/v2/videos.ts","../src/resources/v2/collections.ts","../src/resources/v1/videos.ts","../src/resources/v1/collections.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 trimTrailingSlashes(value: string): string {\n let end = value.length;\n while (end > 0 && value[end - 1] === '/') end--;\n return value.slice(0, end);\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 = trimTrailingSlashes(baseUrl);\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 { 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","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 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"],"names":["createHttpClient","config","baseUrl","apiKey","clientId","fetch","fetchImpl","apiVersion","f","globalThis","Error","baseHeaders","fullUrl","path","test","base","value","end","length","slice","trimTrailingSlashes","relative","replace","encodeURIComponent","startsWith","joinUrl","version","v","toLowerCase","convertToValidAPIVersion","request","async","method","init","body","reqInit","headers","undefined","JSON","stringify","res","ok","text","catch","status","statusText","json","parseJson","get","post","put","patch","delete","BASE_URL","JaaqClient","constructor","http","this","videos","getById","id","video","createVideosResourceV2","collections","collection","createCollectionsResourceV2","createVideosResource","createCollectionsResource","fromHttp","buildClient","createJaaqClient"],"mappings":"8OAkDM,SAAUA,EAAiBC,GAC/B,MAAMC,QAAEA,EAAOC,OAAEA,EAAMC,SAAEA,EAAUC,MAAOC,EAASC,WAAEA,GAAeN,EAE9DO,EAA2BF,GAAcG,WAAWJ,MAC1D,IAAKG,EACH,MAAM,IAAIE,MAAM,kGAGlB,MAAMC,EAAsC,CAC1C,eAAgB,mBAChB,YAAaR,GAGTS,EAAWC,GA3BnB,SAAiBX,EAAiBK,EAAoBH,EAAkBS,GAEtE,GAAI,gBAAgBC,KAAKD,GAAO,OAAOA,EACvC,MAAME,EATR,SAA6BC,GAC3B,IAAIC,EAAMD,EAAME,OAChB,KAAOD,EAAM,GAAwB,MAAnBD,EAAMC,EAAM,IAAYA,IAC1C,OAAOD,EAAMG,MAAM,EAAGF,EACxB,CAKeG,CAAoBlB,GAC3BmB,EAAWR,EAAKS,QAAQ,OAAQ,IACtC,MAAO,GAAGP,SAAYR,kBAA2BgB,mBAAmBnB,KAAYiB,EAASG,WAAW,KAAOH,EAAW,IAAIA,KAC5H,CAqBoCI,CAAQvB,EAnB5C,SAAkCwB,GAChC,MAAMC,EAAID,EAAQE,cAClB,MAAU,OAAND,GAAoB,OAANA,EAAmBA,EAC9B,IACT,CAeqDE,CAAyBtB,GAAaH,EAAUS,GAE7FiB,EAAUC,MAAUC,EAAgBnB,EAAcoB,EAAuBC,KAC7E,MAAMC,EAA0B,CAC9BH,SACAI,QAAS,IACJzB,KACCsB,GAAMG,YAETH,QAEQI,IAATH,IAAoBC,EAAQD,KAAOI,KAAKC,UAAUL,IAEtD,OAvDJH,eAA4BS,GAC1B,IAAKA,EAAIC,GAAI,CACX,MAAMC,QAAaF,EAAIE,OAAOC,MAAM,IAAM,IAC1C,MAAM,IAAIjC,MAAM,QAAQ8B,EAAII,WAAWF,GAAQF,EAAIK,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C,EAAO,gBAAgBU,mBAAmBqC,KAEhD,aADuBJ,EAAKR,IAAmCnC,IAC/CmD,UAClB,EAEJ,CJ4ByBG,CAA0BX,GAEjD,CAOA,eAAOY,CAAuCZ,EAAkBjD,GAC9D,OAAO,IAAI+C,EAAWE,EAAMjD,EAC9B,CAMA,WAAO0B,CAAmChC,GACxC,OAAOoE,EAAYpE,EACrB,EAOI,SAAUqE,EAA+CrE,GAC7D,OAAOoE,EAAYpE,EACrB,CAeA,SAASoE,EAA0CpE,GACjD,MAAMC,QAAEA,EAAUmD,EAAQlD,OAAEA,EAAMC,SAAEA,EAAUC,MAAOC,EAASC,WAAEA,EAAa,MAASN,EAEhFuD,EAAOxD,EAAiB,CAC5BE,UACAC,SACAC,WACAC,MAAOC,GAAcG,WAAWJ,MAChCE,eAGF,OAAO+C,EAAWc,SAASZ,EAAMjD,EACnC,uEAzBM,SAA6BN,GACjC,OAAOqE,EAAiB,IAAKrE,EAAQM,WAAY,MACnD,uBAEM,SAA6BN,GACjC,OAAOqE,EAAiB,IAAKrE,EAAQM,WAAY,MACnD"}
package/dist/ui/index.cjs CHANGED
@@ -11,11 +11,17 @@ async function parseJson(res) {
11
11
  return undefined;
12
12
  return res.json();
13
13
  }
14
+ function trimTrailingSlashes(value) {
15
+ let end = value.length;
16
+ while (end > 0 && value[end - 1] === '/')
17
+ end--;
18
+ return value.slice(0, end);
19
+ }
14
20
  function joinUrl(baseUrl, apiVersion, clientId, path) {
15
21
  // return path if it is an absolute URL
16
22
  if (/^https?:\/\//i.test(path))
17
23
  return path;
18
- const base = baseUrl.replace(/\/+$/, '');
24
+ const base = trimTrailingSlashes(baseUrl);
19
25
  const relative = path.replace(/^\/+/, '');
20
26
  return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
21
27
  }