@jaaq/jaaq-sdk-js 1.1.1 → 1.2.0-dev-ec79f7e-20260605
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -7
- package/dist/embed/embed-collection.html +17 -4
- package/dist/embed/embed.html +15 -3
- package/dist/index.cjs +57 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +100 -24
- package/dist/index.mjs +56 -12
- package/dist/index.mjs.map +1 -1
- package/dist/jaaq-sdk.min.js +1 -1
- package/dist/jaaq-sdk.min.js.map +1 -1
- package/dist/ui/index.cjs +102 -17
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.ts +89 -10
- package/dist/ui/index.mjs +102 -17
- package/dist/ui/index.mjs.map +1 -1
- package/dist/ui/jaaq-ui-bundled.min.js +2 -2
- package/dist/ui/jaaq-ui-bundled.min.js.map +1 -1
- package/dist/ui/jaaq-ui.min.js +2 -2
- package/dist/ui/jaaq-ui.min.js.map +1 -1
- package/dist/ui/react/index.cjs +78 -18
- package/dist/ui/react/index.cjs.map +1 -1
- package/dist/ui/react/index.d.ts +84 -7
- package/dist/ui/react/index.mjs +78 -18
- package/dist/ui/react/index.mjs.map +1 -1
- package/dist/ui/react/jaaq-ui-react.min.js +2 -2
- package/dist/ui/react/jaaq-ui-react.min.js.map +1 -1
- package/dist/ui/vanilla/index.cjs +102 -17
- package/dist/ui/vanilla/index.cjs.map +1 -1
- package/dist/ui/vanilla/index.d.ts +89 -10
- package/dist/ui/vanilla/index.mjs +102 -17
- package/dist/ui/vanilla/index.mjs.map +1 -1
- package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js +2 -2
- package/dist/ui/vanilla/jaaq-vanilla-bundled.min.js.map +1 -1
- package/dist/ui/vanilla/jaaq-vanilla.min.js +2 -2
- package/dist/ui/vanilla/jaaq-vanilla.min.js.map +1 -1
- package/dist/ui/webcomponents/index.cjs +74 -14
- package/dist/ui/webcomponents/index.cjs.map +1 -1
- package/dist/ui/webcomponents/index.d.ts +86 -9
- package/dist/ui/webcomponents/index.mjs +74 -14
- package/dist/ui/webcomponents/index.mjs.map +1 -1
- package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js +2 -2
- package/dist/ui/webcomponents/jaaq-webcomponents-bundled.min.js.map +1 -1
- package/dist/ui/webcomponents/jaaq-webcomponents.min.js +2 -2
- package/dist/ui/webcomponents/jaaq-webcomponents.min.js.map +1 -1
- package/package.json +38 -35
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","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 ?? (globalTh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AAO,IAAI,CAAC,MAAiB,EAAA;AAC3B,QAAA,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B;AACD;AAED;;;AAGG;AACG,SAAU,gBAAgB,CAAC,MAAiB,EAAA;AAChD,IAAA,OAAO,WAAW,CAAC,MAAM,CAAC;AAC5B;AAEA;;;;AAIG;AACH,SAAS,WAAW,CAAC,MAAiB,EAAA;AACpC,IAAA,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM;IAEzE,MAAM,IAAI,GAAG,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.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,OAA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AC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;AAC9C;;;;"}
|
package/dist/jaaq-sdk.min.js
CHANGED
|
@@ -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}=t,
|
|
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"})}});
|
|
2
2
|
//# sourceMappingURL=jaaq-sdk.min.js.map
|
package/dist/jaaq-sdk.min.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jaaq-sdk.min.js","sources":["../src/core/httpClient.ts","../src/index.ts","../src/resources/videos.ts","../src/resources/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 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 { 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","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"],"names":["createHttpClient","config","baseUrl","apiKey","clientId","fetch","fetchImpl","f","globalThis","Error","baseHeaders","fullUrl","path","test","base","replace","relative","encodeURIComponent","startsWith","joinUrl","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","createVideosResource","collections","collection","createCollectionsResource","fromHttp","buildClient"],"mappings":"8OAqCM,SAAUA,EAAiBC,GAC/B,MAAMC,QAAEA,EAAOC,OAAEA,EAAMC,SAAEA,EAAUC,MAAOC,GAAcL,EAElDM,EAA2BD,GAAcE,WAAWH,MAC1D,IAAKE,EACH,MAAM,IAAIE,MAAM,kGAGlB,MAAMC,EAAsC,CAC1C,eAAgB,mBAChB,YAAaP,GAGTQ,EAAWC,GArBnB,SAAiBV,EAAiBE,EAAkBQ,GAElD,GAAI,gBAAgBC,KAAKD,GAAO,OAAOA,EACvC,MAAME,EAAOZ,EAAQa,QAAQ,OAAQ,IAC/BC,EAAWJ,EAAKG,QAAQ,OAAQ,IACtC,MAAO,GAAGD,yBAA4BG,mBAAmBb,KAAYY,EAASE,WAAW,KAAOF,EAAW,IAAIA,KACjH,CAeoCG,CAAQjB,EAASE,EAAUQ,GAEvDQ,EAAUC,MAAUC,EAAgBV,EAAcW,EAAuBC,KAC7E,MAAMC,EAA0B,CAC9BH,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AAOwD,EAAYxD,EACrB,EAgBF,SAASwD,EAAYxD,GACnB,MAAMC,QAAEA,EAAUyC,EAAQxC,OAAEA,EAAMC,SAAEA,EAAUC,MAAOC,GAAcL,EAE7D6C,EAAO9C,EAAiB,CAC5BE,UACAC,SACAC,WACAC,MAAOC,GAAcE,WAAWH,QAGlC,OAAOuC,EAAWY,SAASV,EAC7B,gDApBM,SAA2B7C,GAC/B,OAAOwD,EAAYxD,EACrB"}
|
|
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,EAAUS,GAE7FY,EAAUC,MAAUC,EAAgBd,EAAce,EAAuBC,KA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,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"}
|
package/dist/ui/index.cjs
CHANGED
|
@@ -11,16 +11,22 @@ async function parseJson(res) {
|
|
|
11
11
|
return undefined;
|
|
12
12
|
return res.json();
|
|
13
13
|
}
|
|
14
|
-
function joinUrl(baseUrl, clientId, path) {
|
|
14
|
+
function joinUrl(baseUrl, apiVersion, clientId, path) {
|
|
15
15
|
// return path if it is an absolute URL
|
|
16
16
|
if (/^https?:\/\//i.test(path))
|
|
17
17
|
return path;
|
|
18
18
|
const base = baseUrl.replace(/\/+$/, '');
|
|
19
19
|
const relative = path.replace(/^\/+/, '');
|
|
20
|
-
return `${base}/b2b/
|
|
20
|
+
return `${base}/b2b/${apiVersion}/subscription/${encodeURIComponent(clientId)}${relative.startsWith('/') ? relative : `/${relative}`}`;
|
|
21
|
+
}
|
|
22
|
+
function convertToValidAPIVersion(version) {
|
|
23
|
+
const v = version.toLowerCase();
|
|
24
|
+
if (v === 'v1' || v === 'v2')
|
|
25
|
+
return v;
|
|
26
|
+
return 'v1'; // default to v1 if invalid version provided
|
|
21
27
|
}
|
|
22
28
|
function createHttpClient(config) {
|
|
23
|
-
const { baseUrl, apiKey, clientId, fetch: fetchImpl } = config;
|
|
29
|
+
const { baseUrl, apiKey, clientId, fetch: fetchImpl, apiVersion } = config;
|
|
24
30
|
const f = fetchImpl ?? globalThis.fetch;
|
|
25
31
|
if (!f) {
|
|
26
32
|
throw new Error('No fetch implementation found. Provide one in SDKConfig.fetch for Node or custom environments.');
|
|
@@ -29,7 +35,7 @@ function createHttpClient(config) {
|
|
|
29
35
|
'Content-Type': 'application/json',
|
|
30
36
|
'x-api-key': apiKey,
|
|
31
37
|
};
|
|
32
|
-
const fullUrl = (path) => joinUrl(baseUrl, clientId, path);
|
|
38
|
+
const fullUrl = (path) => joinUrl(baseUrl, convertToValidAPIVersion(apiVersion), clientId, path);
|
|
33
39
|
const request = async (method, path, init, body) => {
|
|
34
40
|
const reqInit = {
|
|
35
41
|
method,
|
|
@@ -78,20 +84,51 @@ function createCollectionsResource(http) {
|
|
|
78
84
|
};
|
|
79
85
|
}
|
|
80
86
|
|
|
87
|
+
function createVideosResourceV2(http) {
|
|
88
|
+
return {
|
|
89
|
+
async getById(id) {
|
|
90
|
+
const path = `/videos/${encodeURIComponent(id)}`;
|
|
91
|
+
const response = await http.get(path);
|
|
92
|
+
return response.video;
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function createCollectionsResourceV2(http) {
|
|
98
|
+
return {
|
|
99
|
+
async list() {
|
|
100
|
+
const path = '/collections';
|
|
101
|
+
const response = await http.get(path);
|
|
102
|
+
return response.collections;
|
|
103
|
+
},
|
|
104
|
+
async getById(id) {
|
|
105
|
+
const path = `/collections/${encodeURIComponent(id)}`;
|
|
106
|
+
const response = await http.get(path);
|
|
107
|
+
return response.collection;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
81
112
|
const BASE_URL = "https://api.jaaq.app";
|
|
82
113
|
class JaaqClient {
|
|
83
114
|
// Keep constructor private to enforce controlled instantiation.
|
|
84
|
-
constructor(http) {
|
|
85
|
-
|
|
86
|
-
|
|
115
|
+
constructor(http, apiVersion) {
|
|
116
|
+
if (apiVersion === 'v2') {
|
|
117
|
+
this.videos = createVideosResourceV2(http);
|
|
118
|
+
this.collections = createCollectionsResourceV2(http);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.videos = createVideosResource(http);
|
|
122
|
+
this.collections = createCollectionsResource(http);
|
|
123
|
+
}
|
|
87
124
|
}
|
|
88
125
|
/**
|
|
89
126
|
* Public "friend" constructor that remains inside the class boundary.
|
|
90
127
|
* This method is callable from the module-level build function
|
|
91
128
|
* without exposing `new JaaqClient(...)` to consumers.
|
|
92
129
|
*/
|
|
93
|
-
static fromHttp(http) {
|
|
94
|
-
return new JaaqClient(http);
|
|
130
|
+
static fromHttp(http, apiVersion) {
|
|
131
|
+
return new JaaqClient(http, apiVersion);
|
|
95
132
|
}
|
|
96
133
|
/**
|
|
97
134
|
* OO-friendly static initializer.
|
|
@@ -114,14 +151,15 @@ function createJaaqClient(config) {
|
|
|
114
151
|
* The constructor stays private; instantiation is funneled via `JaaqClient.fromHttp`.
|
|
115
152
|
*/
|
|
116
153
|
function buildClient(config) {
|
|
117
|
-
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl } = config;
|
|
154
|
+
const { baseUrl = BASE_URL, apiKey, clientId, fetch: fetchImpl, apiVersion = 'v1' } = config;
|
|
118
155
|
const http = createHttpClient({
|
|
119
156
|
baseUrl,
|
|
120
157
|
apiKey,
|
|
121
158
|
clientId,
|
|
122
159
|
fetch: fetchImpl ?? globalThis.fetch,
|
|
160
|
+
apiVersion,
|
|
123
161
|
});
|
|
124
|
-
return JaaqClient.fromHttp(http);
|
|
162
|
+
return JaaqClient.fromHttp(http, apiVersion);
|
|
125
163
|
}
|
|
126
164
|
|
|
127
165
|
/**
|
|
@@ -4053,6 +4091,7 @@ class JaaqCollectionPlayer {
|
|
|
4053
4091
|
apiKey: config.apiKey,
|
|
4054
4092
|
clientId: config.clientId,
|
|
4055
4093
|
baseUrl: config.baseUrl || BASE_URL,
|
|
4094
|
+
apiVersion: config.apiVersion,
|
|
4056
4095
|
});
|
|
4057
4096
|
}
|
|
4058
4097
|
else {
|
|
@@ -4084,7 +4123,8 @@ class JaaqCollectionPlayer {
|
|
|
4084
4123
|
throw new Error('Client is not initialized');
|
|
4085
4124
|
}
|
|
4086
4125
|
this.collectionData = await this.client.collections.getById(collectionId);
|
|
4087
|
-
|
|
4126
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4127
|
+
if (videos.length === 0) {
|
|
4088
4128
|
this.emitError(new Error('No videos found in collection'));
|
|
4089
4129
|
return;
|
|
4090
4130
|
}
|
|
@@ -4105,6 +4145,21 @@ class JaaqCollectionPlayer {
|
|
|
4105
4145
|
</div>
|
|
4106
4146
|
`;
|
|
4107
4147
|
}
|
|
4148
|
+
getVideosFromCollection(collection) {
|
|
4149
|
+
if (collection.videos && collection.videos.length > 0) {
|
|
4150
|
+
return collection.videos;
|
|
4151
|
+
}
|
|
4152
|
+
if (collection.videoGroups && collection.videoGroups.length > 0) {
|
|
4153
|
+
const videos = [];
|
|
4154
|
+
collection.videoGroups.forEach((group) => {
|
|
4155
|
+
if (group.videos && group.videos.length > 0) {
|
|
4156
|
+
videos.push(...group.videos);
|
|
4157
|
+
}
|
|
4158
|
+
});
|
|
4159
|
+
return videos;
|
|
4160
|
+
}
|
|
4161
|
+
return [];
|
|
4162
|
+
}
|
|
4108
4163
|
renderCarousel() {
|
|
4109
4164
|
if (!this.playerElement || !this.collectionData)
|
|
4110
4165
|
return;
|
|
@@ -4115,7 +4170,8 @@ class JaaqCollectionPlayer {
|
|
|
4115
4170
|
track.className = 'splide__track';
|
|
4116
4171
|
const list = document.createElement('ul');
|
|
4117
4172
|
list.className = 'splide__list';
|
|
4118
|
-
this.collectionData
|
|
4173
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4174
|
+
videos.forEach((video) => {
|
|
4119
4175
|
const slide = document.createElement('li');
|
|
4120
4176
|
slide.className = 'splide__slide';
|
|
4121
4177
|
const player = document.createElement('jaaq-video-player');
|
|
@@ -4126,6 +4182,8 @@ class JaaqCollectionPlayer {
|
|
|
4126
4182
|
player.setAttribute('client-id', this.config.clientId);
|
|
4127
4183
|
if (this.config.baseUrl)
|
|
4128
4184
|
player.setAttribute('base-url', this.config.baseUrl);
|
|
4185
|
+
if (this.config.apiVersion)
|
|
4186
|
+
player.setAttribute('api-version', this.config.apiVersion);
|
|
4129
4187
|
player.setAttribute('autoplay', 'false');
|
|
4130
4188
|
player.setAttribute('width', '100%');
|
|
4131
4189
|
if (this.config.videoSettings) {
|
|
@@ -4195,7 +4253,8 @@ class JaaqCollectionPlayer {
|
|
|
4195
4253
|
this.splide.on('moved', (newIndex) => {
|
|
4196
4254
|
this.handleSlideChange(newIndex);
|
|
4197
4255
|
if (this.collectionData) {
|
|
4198
|
-
|
|
4256
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4257
|
+
this.emit('slidechange', { index: newIndex, video: videos[newIndex] });
|
|
4199
4258
|
}
|
|
4200
4259
|
});
|
|
4201
4260
|
this.splide.mount();
|
|
@@ -4340,6 +4399,10 @@ function parseDataAttributes(element) {
|
|
|
4340
4399
|
if (baseUrl) {
|
|
4341
4400
|
config.baseUrl = baseUrl;
|
|
4342
4401
|
}
|
|
4402
|
+
const apiVersion = element.getAttribute('data-api-version');
|
|
4403
|
+
if (apiVersion) {
|
|
4404
|
+
config.apiVersion = apiVersion;
|
|
4405
|
+
}
|
|
4343
4406
|
const className = element.getAttribute('data-class-name');
|
|
4344
4407
|
if (className) {
|
|
4345
4408
|
config.className = className;
|
|
@@ -4522,6 +4585,21 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4522
4585
|
return defaultValue;
|
|
4523
4586
|
return v !== 'false';
|
|
4524
4587
|
}
|
|
4588
|
+
getVideosFromCollection(collection) {
|
|
4589
|
+
if (collection.videos && collection.videos.length > 0) {
|
|
4590
|
+
return collection.videos;
|
|
4591
|
+
}
|
|
4592
|
+
if (collection.videoGroups && collection.videoGroups.length > 0) {
|
|
4593
|
+
const videos = [];
|
|
4594
|
+
collection.videoGroups.forEach((group) => {
|
|
4595
|
+
if (group.videos && group.videos.length > 0) {
|
|
4596
|
+
videos.push(...group.videos);
|
|
4597
|
+
}
|
|
4598
|
+
});
|
|
4599
|
+
return videos;
|
|
4600
|
+
}
|
|
4601
|
+
return [];
|
|
4602
|
+
}
|
|
4525
4603
|
render() {
|
|
4526
4604
|
if (!this.shadowRoot)
|
|
4527
4605
|
return;
|
|
@@ -4548,6 +4626,7 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4548
4626
|
const apiKey = this.getAttribute('api-key');
|
|
4549
4627
|
const clientId = this.getAttribute('client-id');
|
|
4550
4628
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
4629
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
4551
4630
|
if (!this.clientInstance && !apiKey && !clientId) {
|
|
4552
4631
|
this.emitError(new Error('Either client property or api-key and client-id attributes are required'));
|
|
4553
4632
|
return;
|
|
@@ -4559,9 +4638,11 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4559
4638
|
apiKey: apiKey,
|
|
4560
4639
|
clientId: clientId,
|
|
4561
4640
|
baseUrl: baseUrl || BASE_URL,
|
|
4641
|
+
apiVersion: apiVersion,
|
|
4562
4642
|
});
|
|
4563
4643
|
this.collectionData = await client.collections.getById(collectionId);
|
|
4564
|
-
|
|
4644
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4645
|
+
if (videos.length === 0) {
|
|
4565
4646
|
this.emitError(new Error('No videos found in collection'));
|
|
4566
4647
|
return;
|
|
4567
4648
|
}
|
|
@@ -4609,7 +4690,8 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4609
4690
|
console.warn('[CollectionPlayer] Failed to parse video-settings attribute', e);
|
|
4610
4691
|
}
|
|
4611
4692
|
}
|
|
4612
|
-
this.collectionData
|
|
4693
|
+
const videos = this.getVideosFromCollection(this.collectionData);
|
|
4694
|
+
videos.forEach((video) => {
|
|
4613
4695
|
const slide = document.createElement('li');
|
|
4614
4696
|
slide.className = 'splide__slide';
|
|
4615
4697
|
const player = document.createElement('jaaq-video-player');
|
|
@@ -4691,8 +4773,9 @@ class JaaqCollectionPlayerElement extends HTMLElement {
|
|
|
4691
4773
|
Components: this.splide?.Components,
|
|
4692
4774
|
});
|
|
4693
4775
|
this.handleSlideChange(newIndex);
|
|
4776
|
+
const videos = this.collectionData ? this.getVideosFromCollection(this.collectionData) : [];
|
|
4694
4777
|
this.dispatchEvent(new CustomEvent('jaaq:collection:slidechange', {
|
|
4695
|
-
detail: { index: newIndex, video:
|
|
4778
|
+
detail: { index: newIndex, video: videos[newIndex] },
|
|
4696
4779
|
bubbles: true,
|
|
4697
4780
|
composed: true,
|
|
4698
4781
|
}));
|
|
@@ -4974,6 +5057,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
4974
5057
|
const apiKey = this.getAttribute('api-key');
|
|
4975
5058
|
const clientId = this.getAttribute('client-id');
|
|
4976
5059
|
const baseUrl = this.getAttribute('base-url') || undefined;
|
|
5060
|
+
const apiVersion = this.getAttribute('api-version') || undefined;
|
|
4977
5061
|
const autoplay = this.hasAttribute('autoplay') && this.getAttribute('autoplay') !== 'false';
|
|
4978
5062
|
const controls = !this.hasAttribute('controls') || this.getAttribute('controls') !== 'false';
|
|
4979
5063
|
const showLogo = !this.hasAttribute('show-logo') || this.getAttribute('show-logo') !== 'false';
|
|
@@ -4993,6 +5077,7 @@ class JaaqVideoPlayerElement extends HTMLElement {
|
|
|
4993
5077
|
clientId: clientId ?? undefined,
|
|
4994
5078
|
client: this.clientInstance || undefined,
|
|
4995
5079
|
baseUrl,
|
|
5080
|
+
apiVersion,
|
|
4996
5081
|
autoplay,
|
|
4997
5082
|
controls,
|
|
4998
5083
|
showLogo,
|