@jaaq/jaaq-sdk-js 1.4.0 → 1.5.0
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 +6 -0
- package/dist/index.cjs +7 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +7 -2
- 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 +7 -2
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.mjs +7 -2
- 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 +7 -2
- package/dist/ui/react/index.cjs.map +1 -1
- package/dist/ui/react/index.d.ts +4 -0
- package/dist/ui/react/index.mjs +7 -2
- 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 +7 -2
- package/dist/ui/vanilla/index.cjs.map +1 -1
- package/dist/ui/vanilla/index.d.ts +4 -0
- package/dist/ui/vanilla/index.mjs +7 -2
- 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 +7 -2
- package/dist/ui/webcomponents/index.cjs.map +1 -1
- package/dist/ui/webcomponents/index.d.ts +4 -0
- package/dist/ui/webcomponents/index.mjs +7 -2
- 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 +7 -7
package/README.md
CHANGED
|
@@ -79,6 +79,12 @@ const clientV2 = createJaaqClientV2({
|
|
|
79
79
|
const collection = await clientV2.collections.getById('collection-id', { subdomain: 'natwest' });
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
+
When only the collection's `name` and `series` are needed, `collections.getSummaryById` returns `{ id, name, series }` without the collection's videos. It takes the same `subdomain` option, and without it `series` is empty.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const { name, series } = await clientV2.collections.getSummaryById('collection-id', { subdomain: 'natwest' });
|
|
86
|
+
```
|
|
87
|
+
|
|
82
88
|
### Client config
|
|
83
89
|
|
|
84
90
|
| Option | Type | Required | Default | Notes |
|
package/dist/index.cjs
CHANGED
|
@@ -98,6 +98,7 @@ function createVideosResourceV2(http) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
const subdomainQuery = (options) => options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';
|
|
101
102
|
function createCollectionsResourceV2(http) {
|
|
102
103
|
return {
|
|
103
104
|
async list() {
|
|
@@ -106,8 +107,12 @@ function createCollectionsResourceV2(http) {
|
|
|
106
107
|
return response.collections;
|
|
107
108
|
},
|
|
108
109
|
async getById(id, options) {
|
|
109
|
-
const
|
|
110
|
-
const
|
|
110
|
+
const path = `/collections/${encodeURIComponent(id)}${subdomainQuery(options)}`;
|
|
111
|
+
const response = await http.get(path);
|
|
112
|
+
return response.collection;
|
|
113
|
+
},
|
|
114
|
+
async getSummaryById(id, options) {
|
|
115
|
+
const path = `/collections/${encodeURIComponent(id)}/summary${subdomainQuery(options)}`;
|
|
111
116
|
const response = await http.get(path);
|
|
112
117
|
return response.collection;
|
|
113
118
|
},
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 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, GetCollectionByIdV2Options } from '@src/types';\n\nexport type CollectionsResourceV2 = {\n list(): Promise<CollectionV2DTO[]>;\n getById(_id: string, _options?: GetCollectionByIdV2Options): 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, options?: GetCollectionByIdV2Options) {\n const query = options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';\n const path = `/collections/${encodeURIComponent(id)}${query}`;\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,mBAAmB,CAAC,KAAa,EAAA;AACxC,IAAA,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM;IACtB,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG;AAAE,QAAA,GAAG,EAAE;IAC/C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;AAC5B;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;AAC3C,IAAA,MAAM,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CA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E,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
|
+
{"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 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 { CollectionSummaryV2DTO, CollectionV2DTO, GetCollectionByIdV2Options } from '@src/types';\n\nexport type CollectionsResourceV2 = {\n list(): Promise<CollectionV2DTO[]>;\n getById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionV2DTO>;\n getSummaryById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionSummaryV2DTO>;\n};\n\nconst subdomainQuery = (options?: GetCollectionByIdV2Options) =>\n options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';\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, options?: GetCollectionByIdV2Options) {\n const path = `/collections/${encodeURIComponent(id)}${subdomainQuery(options)}`;\n const response = await http.get<{ collection: CollectionV2DTO }>(path);\n return response.collection;\n },\n async getSummaryById(id: string, options?: GetCollectionByIdV2Options) {\n const path = `/collections/${encodeURIComponent(id)}/summary${subdomainQuery(options)}`;\n const response = await http.get<{ collection: CollectionSummaryV2DTO }>(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,mBAAmB,CAAC,KAAa,EAAA;AACxC,IAAA,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM;IACtB,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC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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
|
@@ -107,6 +107,9 @@ type CollectionV2DTO = {
|
|
|
107
107
|
} | null;
|
|
108
108
|
videoGroups: VideoGroupV2DTO[];
|
|
109
109
|
};
|
|
110
|
+
type CollectionSummaryV2DTO = Pick<CollectionV2DTO, 'id' | 'name'> & {
|
|
111
|
+
series: string[];
|
|
112
|
+
};
|
|
110
113
|
type GetCollectionByIdV2Options = {
|
|
111
114
|
subdomain?: string;
|
|
112
115
|
};
|
|
@@ -127,6 +130,7 @@ type VideosResourceV2 = {
|
|
|
127
130
|
type CollectionsResourceV2 = {
|
|
128
131
|
list(): Promise<CollectionV2DTO[]>;
|
|
129
132
|
getById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionV2DTO>;
|
|
133
|
+
getSummaryById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionSummaryV2DTO>;
|
|
130
134
|
};
|
|
131
135
|
|
|
132
136
|
declare const BASE_URL: string;
|
|
@@ -172,4 +176,4 @@ declare function createJaaqClientV1(config: SDKConfig): JaaqClient<V1>;
|
|
|
172
176
|
declare function createJaaqClientV2(config: SDKConfig): JaaqClient<V2>;
|
|
173
177
|
|
|
174
178
|
export { BASE_URL, JaaqClient, createJaaqClient, createJaaqClientV1, createJaaqClientV2 };
|
|
175
|
-
export type { ApiError, ClientVersion, CollectionDTO, CollectionV2DTO, CreatorV2DTO, CtaV2DTO, GetCollectionByIdV2Options, ISODateTimeString, SDKConfig, SubtitleV2DTO, Subtopic, V1, V2, VideoDTO, VideoGroupV2DTO, VideoV2DTO };
|
|
179
|
+
export type { ApiError, ClientVersion, CollectionDTO, CollectionSummaryV2DTO, CollectionV2DTO, CreatorV2DTO, CtaV2DTO, GetCollectionByIdV2Options, ISODateTimeString, SDKConfig, SubtitleV2DTO, Subtopic, V1, V2, VideoDTO, VideoGroupV2DTO, VideoV2DTO };
|
package/dist/index.mjs
CHANGED
|
@@ -96,6 +96,7 @@ function createVideosResourceV2(http) {
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
const subdomainQuery = (options) => options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';
|
|
99
100
|
function createCollectionsResourceV2(http) {
|
|
100
101
|
return {
|
|
101
102
|
async list() {
|
|
@@ -104,8 +105,12 @@ function createCollectionsResourceV2(http) {
|
|
|
104
105
|
return response.collections;
|
|
105
106
|
},
|
|
106
107
|
async getById(id, options) {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
108
|
+
const path = `/collections/${encodeURIComponent(id)}${subdomainQuery(options)}`;
|
|
109
|
+
const response = await http.get(path);
|
|
110
|
+
return response.collection;
|
|
111
|
+
},
|
|
112
|
+
async getSummaryById(id, options) {
|
|
113
|
+
const path = `/collections/${encodeURIComponent(id)}/summary${subdomainQuery(options)}`;
|
|
109
114
|
const response = await http.get(path);
|
|
110
115
|
return response.collection;
|
|
111
116
|
},
|
package/dist/index.mjs.map
CHANGED
|
@@ -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 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, GetCollectionByIdV2Options } from '@src/types';\n\nexport type CollectionsResourceV2 = {\n list(): Promise<CollectionV2DTO[]>;\n getById(_id: string, _options?: GetCollectionByIdV2Options): 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, options?: GetCollectionByIdV2Options) {\n const query = options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';\n const path = `/collections/${encodeURIComponent(id)}${query}`;\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,mBAAmB,CAAC,KAAa,EAAA;AACxC,IAAA,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM;IACtB,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG;AAAE,QAAA,GAAG,EAAE;IAC/C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;AAC5B;AAEA,SAAS,OAAO,CAAC,OAAe,EAA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BAAgB,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
|
+
{"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 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 { CollectionSummaryV2DTO, CollectionV2DTO, GetCollectionByIdV2Options } from '@src/types';\n\nexport type CollectionsResourceV2 = {\n list(): Promise<CollectionV2DTO[]>;\n getById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionV2DTO>;\n getSummaryById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionSummaryV2DTO>;\n};\n\nconst subdomainQuery = (options?: GetCollectionByIdV2Options) =>\n options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';\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, options?: GetCollectionByIdV2Options) {\n const path = `/collections/${encodeURIComponent(id)}${subdomainQuery(options)}`;\n const response = await http.get<{ collection: CollectionV2DTO }>(path);\n return response.collection;\n },\n async getSummaryById(id: string, options?: GetCollectionByIdV2Options) {\n const path = `/collections/${encodeURIComponent(id)}/summary${subdomainQuery(options)}`;\n const response = await http.get<{ collection: CollectionSummaryV2DTO }>(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,MA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q-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,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),u=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)=>u("GET",t,e),post:(t,e,n)=>u("POST",t,n,e),put:(t,e,n)=>u("PUT",t,n,e),patch:(t,e,n)=>u("PATCH",t,n,e),delete:(t,e)=>u("DELETE",t,e)}}const n="https://api.jaaq.app";class
|
|
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),u=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)=>u("GET",t,e),post:(t,e,n)=>u("POST",t,n,e),put:(t,e,n)=>u("PUT",t,n,e),patch:(t,e,n)=>u("PATCH",t,n,e),delete:(t,e)=>u("DELETE",t,e)}}const n=t=>void 0!==t?.subdomain?`?subdomain=${encodeURIComponent(t.subdomain)}`:"";const o="https://api.jaaq.app";class i{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,o){const i=`/collections/${encodeURIComponent(e)}${n(o)}`;return(await t.get(i)).collection},async getSummaryById(e,o){const i=`/collections/${encodeURIComponent(e)}/summary${n(o)}`;return(await t.get(i)).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 i(t,e)}static init(t){return s(t)}}function c(t){return s(t)}function s(t){const{baseUrl:n=o,apiKey:c,clientId:s,fetch:r,apiVersion:a="v1"}=t,u=e({baseUrl:n,apiKey:c,clientId:s,fetch:r??globalThis.fetch,apiVersion:a});return i.fromHttp(u,a)}t.BASE_URL=o,t.JaaqClient=i,t.createJaaqClient=c,t.createJaaqClientV1=function(t){return c({...t,apiVersion:"v1"})},t.createJaaqClientV2=function(t){return c({...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/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, GetCollectionByIdV2Options } from '@src/types';\n\nexport type CollectionsResourceV2 = {\n list(): Promise<CollectionV2DTO[]>;\n getById(_id: string, _options?: GetCollectionByIdV2Options): 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, options?: GetCollectionByIdV2Options) {\n const query = options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';\n const path = `/collections/${encodeURIComponent(id)}${query}`;\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","options","query","subdomain","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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C,OAAOwE,EAAiB,IAAKxE,EAAQM,WAAY,MACnD,uBAEM,SAA6BN,GACjC,OAAOwE,EAAiB,IAAKxE,EAAQM,WAAY,MACnD"}
|
|
1
|
+
{"version":3,"file":"jaaq-sdk.min.js","sources":["../src/core/httpClient.ts","../src/resources/v2/collections.ts","../src/index.ts","../src/resources/v2/videos.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 type { HttpClient } from '@core/httpClient';\nimport type { CollectionSummaryV2DTO, CollectionV2DTO, GetCollectionByIdV2Options } from '@src/types';\n\nexport type CollectionsResourceV2 = {\n list(): Promise<CollectionV2DTO[]>;\n getById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionV2DTO>;\n getSummaryById(_id: string, _options?: GetCollectionByIdV2Options): Promise<CollectionSummaryV2DTO>;\n};\n\nconst subdomainQuery = (options?: GetCollectionByIdV2Options) =>\n options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';\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, options?: GetCollectionByIdV2Options) {\n const path = `/collections/${encodeURIComponent(id)}${subdomainQuery(options)}`;\n const response = await http.get<{ collection: CollectionV2DTO }>(path);\n return response.collection;\n },\n async getSummaryById(id: string, options?: GetCollectionByIdV2Options) {\n const path = `/collections/${encodeURIComponent(id)}/summary${subdomainQuery(options)}`;\n const response = await http.get<{ collection: CollectionSummaryV2DTO }>(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","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 { 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","subdomainQuery","options","subdomain","BASE_URL","JaaqClient","constructor","http","this","videos","getById","id","video","createVideosResourceV2","collections","collection","getSummaryById","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,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EACrB,EAOI,SAAUyE,EAA+CzE,GAC7D,OAAOwE,EAAYxE,EACrB,CAeA,SAASwE,EAA0CxE,GACjD,MAAMC,QAAEA,EAAUsD,EAAQrD,OAAEA,EAAMC,SAAEA,EAAUC,MAAOC,EAASC,WAAEA,EAAa,MAASN,EAEhF0D,EAAO3D,EAAiB,CAC5BE,UACAC,SACAC,WACAC,MAAOC,GAAcG,WAAWJ,MAChCE,eAGF,OAAOkD,EAAWe,SAASb,EAAMpD,EACnC,uEAzBM,SAA6BN,GACjC,OAAOyE,EAAiB,IAAKzE,EAAQM,WAAY,MACnD,uBAEM,SAA6BN,GACjC,OAAOyE,EAAiB,IAAKzE,EAAQM,WAAY,MACnD"}
|
package/dist/ui/index.cjs
CHANGED
|
@@ -100,6 +100,7 @@ function createVideosResourceV2(http) {
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
const subdomainQuery = (options) => options?.subdomain !== undefined ? `?subdomain=${encodeURIComponent(options.subdomain)}` : '';
|
|
103
104
|
function createCollectionsResourceV2(http) {
|
|
104
105
|
return {
|
|
105
106
|
async list() {
|
|
@@ -108,8 +109,12 @@ function createCollectionsResourceV2(http) {
|
|
|
108
109
|
return response.collections;
|
|
109
110
|
},
|
|
110
111
|
async getById(id, options) {
|
|
111
|
-
const
|
|
112
|
-
const
|
|
112
|
+
const path = `/collections/${encodeURIComponent(id)}${subdomainQuery(options)}`;
|
|
113
|
+
const response = await http.get(path);
|
|
114
|
+
return response.collection;
|
|
115
|
+
},
|
|
116
|
+
async getSummaryById(id, options) {
|
|
117
|
+
const path = `/collections/${encodeURIComponent(id)}/summary${subdomainQuery(options)}`;
|
|
113
118
|
const response = await http.get(path);
|
|
114
119
|
return response.collection;
|
|
115
120
|
},
|