diff --git a/examples/example-1.js b/examples/example-1.js index 6e321b0..e8009df 100644 --- a/examples/example-1.js +++ b/examples/example-1.js @@ -1,11 +1,11 @@ import {PCastApi} from '../dist/node/index.js'; const applicationCredentials = { - id: 'phenixrts.com-alex.zinn', - secret: 'AMAsDzr.dIuGMZ.Zu52Dt~MQvP!DZwYg' -} + id: 'phenixrts.com-alex.zinn', + secret: 'AMAsDzr.dIuGMZ.Zu52Dt~MQvP!DZwYg' +}; const pcastUri = 'https://pcast-stg.phenixrts.com'; const pcastApi = new PCastApi(pcastUri, applicationCredentials); -pcastApi.channels.list().then(console.log); \ No newline at end of file +pcastApi.channels.list().then(console.log); diff --git a/package.json b/package.json index 43697cc..b8a4a6f 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,20 @@ { "name": "@techniker-me/pcast-api", - "version": "2025.0.1", + "version": "2025.0.2", "module": "src/index.ts", "type": "module", "scripts": { - "clean": "bash scripts/clean.sh", - "ci-build": "bun run build:node && bun run build:browser", + "format": "prettier --write ./", + "test": "bun test", + "test:watch": "bun test --watch", + "test:coverage": "bun test --coverage", + "build": "bun run build:node && bun run build:browser && bun run build:types", + "ci-build": "bun run build:node && bun run build:browser && bun run build:types", "build:node": "bun build src/index.ts --outdir dist/node --target node --format esm --minify --production", - "build:browser": "bun build src/index.ts --outdir dist/browser --target browser --format esm --minify --production" + "build:browser": "bun build src/index.ts --outdir dist/browser --target browser --format esm --minify --production", + "build:types": "tsc --outDir dist/types", + "prepublishOnly": "bun run build", + "clean": "rm -rf dist" }, "devDependencies": { "@types/bun": "latest", @@ -19,10 +26,19 @@ "peerDependencies": { "typescript": "^5" }, + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/node/index.js", + "default": "./dist/node/index.js" + }, + "./browser": "./dist/browser/index.js" + }, "publishConfig": { "registry": "https://registry-node.techniker.me" }, "dependencies": { - "@types/node": "24.3.0" + "@types/node": "24.3.0", + "phenix-edge-auth": "1.2.7" } -} \ No newline at end of file +} diff --git a/src/pcast/IResponse.ts b/src/pcast/IResponse.ts index b45cb57..67c9233 100644 --- a/src/pcast/IResponse.ts +++ b/src/pcast/IResponse.ts @@ -17,3 +17,11 @@ export interface ChannelsResponse extends IResponse<'channels', Channel[]> { export interface MembersResponse extends IResponse<'members', Channel[]> { members: Channel[]; } + +export interface PublishingReportResponse extends IResponse<'publishingReport', string> { + publishingReport: string; +} + +export interface ViewingReportResponse extends IResponse<'viewingReport', string> { + viewingReport: string; +} diff --git a/src/pcast/Reporting.ts b/src/pcast/Reporting.ts index 996cca2..3a3dff5 100644 --- a/src/pcast/Reporting.ts +++ b/src/pcast/Reporting.ts @@ -1,7 +1,7 @@ -import assertUnreachable from '../lang/assertUnreachable'; import {HttpMethod} from '../net/http/HttpMethod'; -import type IResponse from './IResponse'; -import type { PCastHttpRequests } from './PCastRequests'; +import type {PCastHttpRequests} from './PCastRequests'; +import type {PublishingReportResponse, ViewingReportResponse} from './IResponse'; +import assertUnreachable from '../lang/assertUnreachable'; export enum ReportKind { Publishing = 0, @@ -42,7 +42,7 @@ export type PublishingReportOptions = { channelIds?: string[]; channelAliases?: string[]; roomIds?: string[]; - roomAliases?:string[]; + roomAliases?: string[]; tags?: string[]; start: string; end: string; @@ -57,7 +57,7 @@ export enum ViewingReportKind { export type ViewingReportKindType = 'RealTime' | 'HLS' | 'DASH'; export type ViewingReportOptions = { - kind: ViewingReportKind, + kind: ViewingReportKind; applicationIds?: string[]; streamIds?: string[]; sessionIds?: string[]; @@ -66,15 +66,12 @@ export type ViewingReportOptions = { channelIds?: string[]; channelAliases?: string[]; roomIds?: string[]; - roomAliases?:string[]; + roomAliases?: string[]; tags?: string[]; start: string; end: string; - - }; - export class Reporting { private readonly _httpRequests: PCastHttpRequests; @@ -97,36 +94,44 @@ export class Reporting { } public async requestPublishingReport(options: PublishingReportOptions): Promise { - if (!(options.start || options.end)) { throw new Error('[Reporting] [requestPublishingReport] requires a start and end Date'); } const publishingReportOptions = { - ...options + ...options }; const requestPublishingOptions = { - body: JSON.stringify({publishingReport: publishingReportOptions}) - + body: JSON.stringify({publishingReport: publishingReportOptions}) }; - const response = await this._httpRequests.request>(HttpMethod.PUT, '/pcast/reporting/publishing', requestPublishingOptions); - - return response; + const response = await this._httpRequests.request( + HttpMethod.PUT, + '/pcast/reporting/publishing', + requestPublishingOptions + ); + if (!response.publishingReport) { + throw new Error('[Reporting] [requestPublishingReport] Invalid response format - missing publishingReport data'); } - private async requestViewingReport(options: ViewingReportOptions): Promise { - const viewingReportOptions = { - ...options - }; - - const requestViewingOptions = { - body: JSON.stringify({viewingReport: viewingReportOptions}) - }; + return response.publishingReport; + } - const response = await this._httpRequests.request>(HttpMethod.PUT, '/pcast/reporting/viewing', requestViewingOptions); + private async requestViewingReport(options: ViewingReportOptions): Promise { + const viewingReportOptions = { + ...options + }; - return response; + const requestViewingOptions = { + body: JSON.stringify({viewingReport: viewingReportOptions}) + }; + + const response = await this._httpRequests.request(HttpMethod.PUT, '/pcast/reporting/viewing', requestViewingOptions); + + if (!response.viewingReport) { + throw new Error('[Reporting] [requestViewingReport] Invalid response format - missing viewingReport data'); } + return response.viewingReport; + } } diff --git a/src/pcast/Stream.ts b/src/pcast/Stream.ts index 3771dc5..8268b29 100644 --- a/src/pcast/Stream.ts +++ b/src/pcast/Stream.ts @@ -1,33 +1,29 @@ - -import { HttpMethod } from "../net/http/HttpMethod"; -import type IResponse from "./IResponse"; -import type { PCastHttpRequests } from "./PCastRequests"; +import {HttpMethod} from '../net/http/HttpMethod'; +import type IResponse from './IResponse'; +import type {PCastHttpRequests} from './PCastRequests'; export class Streams { - private readonly _httpRequests: PCastHttpRequests; + private readonly _httpRequests: PCastHttpRequests; - constructor(httpRequests: PCastHttpRequests) { - this._httpRequests = httpRequests; + constructor(httpRequests: PCastHttpRequests) { + this._httpRequests = httpRequests; + } + + public async publishUri(mediaUri: string, token: string) { + const mediaType = mediaUri.split('.')?.at(-1); + + if (!mediaType) { + throw new Error('Invalid media URI no media type found'); } + const response = await this._httpRequests.request>(HttpMethod.PUT, `/stream/publish/uri/${mediaType}`, { + body: JSON.stringify({ + token, + uri: mediaUri, + options: [] + }) + }); - public async publishUri(mediaUri: string, token: string) { - const mediaType = mediaUri.split('.')?.at(-1); - - if (!mediaType) { - throw new Error('Invalid media URI no media type found'); - } - - - const response = await this._httpRequests.request>(HttpMethod.PUT, `/stream/publish/uri/${mediaType}`, { - body: JSON.stringify({ - token, - uri: mediaUri, - options: [] - }) - }); - - return response; - } - -} \ No newline at end of file + return response; + } +} diff --git a/tsconfig.json b/tsconfig.json index bfa0fea..728a03e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,5 +25,7 @@ "noUnusedLocals": false, "noUnusedParameters": false, "noPropertyAccessFromIndexSignature": false - } -} + }, + "include": ["src"], + "exclude": ["test", "dist", "node_modules"] +} \ No newline at end of file