diff --git a/CHANGELOG.md b/CHANGELOG.md index 469489f..3f059ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All changes to this project will be documented in this file. +## [2.5.7] - 2024-04-23 +- Add *WithResponseHeaders() methods + ## [2.5.6] - 2024-02-19 - Update VideoStatusIngest enum diff --git a/README.md b/README.md index 8f7ed3e..4f291a0 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ - [WatermarksApi](#watermarksapi) - [WebhooksApi](#webhooksapi) - [Models](#models) + - [Rate Limiting](#rate-limiting) - [Authorization](#authorization) - [API key](#api-key) - [Get the access token](#get-the-access-token) @@ -280,6 +281,24 @@ Method | Description | HTTP request - [WebhooksListResponse](https://github.com/apivideo/api.video-nodejs-client/blob/main/docs/model/WebhooksListResponse.md) +### Rate Limiting + +api.video implements rate limiting to ensure fair usage and stability of the service. The API provides the rate limit values in the response headers for any API requests you make. The /auth endpoint is the only route without rate limitation. + +In this Node.js client, you can access these headers by using the `*WithResponseHeaders()` versions of the methods. These methods return both the response body and the headers, allowing you to check the `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Retry-After` headers to understand your current rate limit status. + +Read more about these response headers in the [API reference](https://docs.api.video/reference#limitation). + +Here is an example of how to use these methods: + +```js +const client = new ApiVideoClient({ apiKey: "YOUR_API_KEY" }); +const { body: videos, headers } = await client.videos.listWithResponseHeaders(); +console.log('Rate Limit:', headers['x-ratelimit-limit']); +console.log('Rate Limit Remaining:', headers['x-ratelimit-remaining']); +console.log('Rate Limit Retry after:', headers['x-ratelimit-retry-after']); +``` + ### Authorization #### API key diff --git a/package.json b/package.json index 6058fb1..0b7106d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@api.video/nodejs-client", - "version": "2.5.6", + "version": "2.5.7", "description": "api.video nodejs API client", "keywords": [ "api.video", diff --git a/src/HttpClient.ts b/src/HttpClient.ts index fe984ec..e0fe5ae 100644 --- a/src/HttpClient.ts +++ b/src/HttpClient.ts @@ -24,6 +24,21 @@ export type QueryOptions = { onUploadProgress?: (progressEvent: AxiosProgressEvent) => void; }; +export type ApiResponseHeaders = { + server: string; + 'content-type': string; + 'transfer-encoding': string; + connection: string; + 'cache-control': string; + date: string; + 'x-ratelimit-remaining': string; + 'x-ratelimit-retry-after': string; + 'x-ratelimit-limit': string; + 'x-server': string; + 'access-control-allow-origin': string; + 'timing-allow-origin': string; +}; + export default class HttpClient { private apiKey?: string; private baseUri: string; @@ -44,7 +59,7 @@ export default class HttpClient { this.chunkSize = params.chunkSize; this.headers = new AxiosHeaders({ Accept: 'application/json, */*;q=0.8', - 'AV-Origin-Client': 'nodejs:2.5.6', + 'AV-Origin-Client': 'nodejs:2.5.7', Authorization: this.apiKey ? `Basic ${encode(`${this.apiKey}:`)}` : '', ...(params.applicationName && params.applicationVersion ? { diff --git a/src/api/AdvancedAuthenticationApi.ts b/src/api/AdvancedAuthenticationApi.ts index 5fbfa92..8427128 100644 --- a/src/api/AdvancedAuthenticationApi.ts +++ b/src/api/AdvancedAuthenticationApi.ts @@ -10,7 +10,7 @@ */ import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import AccessToken from '../model/AccessToken'; import AuthenticatePayload from '../model/AuthenticatePayload'; import RefreshTokenPayload from '../model/RefreshTokenPayload'; @@ -33,6 +33,19 @@ export default class AdvancedAuthenticationApi { public async authenticate( authenticatePayload: AuthenticatePayload ): Promise { + return this.authenticateWithResponseHeaders(authenticatePayload).then( + (res) => res.body + ); + } + + /** + * Returns a bearer token that can be used to authenticate other endpoint. You can find the tutorial on using the disposable bearer token [here](https://docs.api.video/reference/disposable-bearer-token-authentication). + * Get Bearer Token + * @param authenticatePayload + */ + public async authenticateWithResponseHeaders( + authenticatePayload: AuthenticatePayload + ): Promise<{ headers: ApiResponseHeaders; body: AccessToken }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (authenticatePayload === null || authenticatePayload === undefined) { @@ -60,19 +73,19 @@ export default class AdvancedAuthenticationApi { queryParams.method = 'POST'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'AccessToken', - '' - ) as AccessToken - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'AccessToken', + '' + ) as AccessToken, + }; + }); } /** @@ -83,6 +96,19 @@ export default class AdvancedAuthenticationApi { public async refresh( refreshTokenPayload: RefreshTokenPayload ): Promise { + return this.refreshWithResponseHeaders(refreshTokenPayload).then( + (res) => res.body + ); + } + + /** + * Accepts the old bearer token and returns a new bearer token that can be used to authenticate other endpoint. You can find the tutorial on using the disposable bearer token [here](https://docs.api.video/reference/disposable-bearer-token-authentication). + * Refresh Bearer Token + * @param refreshTokenPayload + */ + public async refreshWithResponseHeaders( + refreshTokenPayload: RefreshTokenPayload + ): Promise<{ headers: ApiResponseHeaders; body: AccessToken }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (refreshTokenPayload === null || refreshTokenPayload === undefined) { @@ -110,18 +136,18 @@ export default class AdvancedAuthenticationApi { queryParams.method = 'POST'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'AccessToken', - '' - ) as AccessToken - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'AccessToken', + '' + ) as AccessToken, + }; + }); } } diff --git a/src/api/AnalyticsApi.ts b/src/api/AnalyticsApi.ts index 4ce5a5a..903c825 100644 --- a/src/api/AnalyticsApi.ts +++ b/src/api/AnalyticsApi.ts @@ -11,7 +11,7 @@ import { URLSearchParams } from 'url'; import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import AnalyticsPlaysResponse from '../model/AnalyticsPlaysResponse'; /** @@ -35,7 +35,37 @@ export default class AnalyticsApi { * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. */ - public async getLiveStreamsPlays({ + public async getLiveStreamsPlays(args: { + from: string; + dimension: + | 'liveStreamId' + | 'emittedAt' + | 'country' + | 'deviceType' + | 'operatingSystem' + | 'browser'; + to?: string; + filter?: string; + currentPage?: number; + pageSize?: number; + }): Promise { + return this.getLiveStreamsPlaysWithResponseHeaders(args).then( + (res) => res.body + ); + } + + /** + * Retrieve filtered analytics about the number of plays for your live streams in a project. + * Get play events for live stream + * @param {Object} searchParams + * @param { string } searchParams.from Use this query parameter to set the start date for the time period that you want analytics for. - The API returns analytics data including the day you set in `from`. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. + * @param { 'liveStreamId' | 'emittedAt' | 'country' | 'deviceType' | 'operatingSystem' | 'browser' } searchParams.dimension Use this query parameter to define the dimension that you want analytics for. - `liveStreamId`: Returns analytics based on the public live stream identifiers. - `emittedAt`: Returns analytics based on the times of the play events. The API returns data in specific interval groups. When the date period you set in `from` and `to` is less than or equals to 2 days, the response for this dimension is grouped in hourly intervals. Otherwise, it is grouped in daily intervals. - `country`: Returns analytics based on the viewers' country. The list of supported country names are based on the [GeoNames public database](https://www.geonames.org/countries/). - `deviceType`: Returns analytics based on the type of device used by the viewers during the play event. Possible response values are: `computer`, `phone`, `tablet`, `tv`, `console`, `wearable`, `unknown`. - `operatingSystem`: Returns analytics based on the operating system used by the viewers during the play event. Response values include `windows`, `mac osx`, `android`, `ios`, `linux`. - `browser`: Returns analytics based on the browser used by the viewers during the play event. Response values include `chrome`, `firefox`, `edge`, `opera`. + * @param { string } searchParams.to Use this optional query parameter to set the end date for the time period that you want analytics for. - If you do not specify a `to` date, the API returns analytics data starting from the `from` date up until today, and excluding today. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. + * @param { string } searchParams.filter Use this query parameter to filter your results to a specific live stream in a project that you want analytics for. You must use the `liveStreamId:` prefix when specifying a live stream ID. + * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 + * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. + */ + public async getLiveStreamsPlaysWithResponseHeaders({ from, dimension, to, @@ -55,7 +85,7 @@ export default class AnalyticsApi { filter?: string; currentPage?: number; pageSize?: number; - }): Promise { + }): Promise<{ headers: ApiResponseHeaders; body: AnalyticsPlaysResponse }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (from === null || from === undefined) { @@ -119,19 +149,19 @@ export default class AnalyticsApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'AnalyticsPlaysResponse', - '' - ) as AnalyticsPlaysResponse - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'AnalyticsPlaysResponse', + '' + ) as AnalyticsPlaysResponse, + }; + }); } /** @@ -145,7 +175,35 @@ export default class AnalyticsApi { * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. */ - public async getVideosPlays({ + public async getVideosPlays(args: { + from: string; + dimension: + | 'videoId' + | 'emittedAt' + | 'country' + | 'deviceType' + | 'operatingSystem' + | 'browser'; + to?: string; + filter?: string; + currentPage?: number; + pageSize?: number; + }): Promise { + return this.getVideosPlaysWithResponseHeaders(args).then((res) => res.body); + } + + /** + * Retrieve filtered analytics about the number of plays for your videos in a project. + * Get play events for video + * @param {Object} searchParams + * @param { string } searchParams.from Use this query parameter to set the start date for the time period that you want analytics for. - The API returns analytics data including the day you set in `from`. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. + * @param { 'videoId' | 'emittedAt' | 'country' | 'deviceType' | 'operatingSystem' | 'browser' } searchParams.dimension Use this query parameter to define the dimension that you want analytics for. - `videoId`: Returns analytics based on the public video identifiers. - `emittedAt`: Returns analytics based on the times of the play events. The API returns data in specific interval groups. When the date period you set in `from` and `to` is less than or equals to 2 days, the response for this dimension is grouped in hourly intervals. Otherwise, it is grouped in daily intervals. - `country`: Returns analytics based on the viewers' country. The list of supported country names are based on the [GeoNames public database](https://www.geonames.org/countries/). - `deviceType`: Returns analytics based on the type of device used by the viewers during the play event. Possible response values are: `computer`, `phone`, `tablet`, `tv`, `console`, `wearable`, `unknown`. - `operatingSystem`: Returns analytics based on the operating system used by the viewers during the play event. Response values include `windows`, `mac osx`, `android`, `ios`, `linux`. - `browser`: Returns analytics based on the browser used by the viewers during the play event. Response values include `chrome`, `firefox`, `edge`, `opera`. + * @param { string } searchParams.to Use this optional query parameter to set the end date for the time period that you want analytics for. - If you do not specify a `to` date, the API returns analytics data starting from the `from` date up until today, and excluding today. - The date you set must be **within the last 30 days**. - The value you provide must follow the `YYYY-MM-DD` format. + * @param { string } searchParams.filter Use this query parameter to filter your results to a specific video in a project that you want analytics for. You must use the `videoId:` prefix when specifying a video ID. + * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 + * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. + */ + public async getVideosPlaysWithResponseHeaders({ from, dimension, to, @@ -165,7 +223,7 @@ export default class AnalyticsApi { filter?: string; currentPage?: number; pageSize?: number; - }): Promise { + }): Promise<{ headers: ApiResponseHeaders; body: AnalyticsPlaysResponse }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (from === null || from === undefined) { @@ -229,18 +287,18 @@ export default class AnalyticsApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'AnalyticsPlaysResponse', - '' - ) as AnalyticsPlaysResponse - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'AnalyticsPlaysResponse', + '' + ) as AnalyticsPlaysResponse, + }; + }); } } diff --git a/src/api/CaptionsApi.ts b/src/api/CaptionsApi.ts index 0c66629..c7f0890 100644 --- a/src/api/CaptionsApi.ts +++ b/src/api/CaptionsApi.ts @@ -14,7 +14,7 @@ import { createReadStream } from 'fs'; import { URLSearchParams } from 'url'; import FormData from 'form-data'; import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import Caption from '../model/Caption'; import CaptionsListResponse from '../model/CaptionsListResponse'; import CaptionsUpdatePayload from '../model/CaptionsUpdatePayload'; @@ -43,6 +43,23 @@ export default class CaptionsApi { language: string, file: string | Readable | Buffer ): Promise { + return this.uploadWithResponseHeaders(videoId, language, file).then( + (res) => res.body + ); + } + + /** + * Upload a VTT file to add captions to your video. More information can be found [here](https://docs.api.video/vod/add-captions) + * Upload a caption + * @param videoId The unique identifier for the video you want to add a caption to. + * @param language A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + * @param file The video text track (VTT) you want to upload. + */ + public async uploadWithResponseHeaders( + videoId: string, + language: string, + file: string | Readable | Buffer + ): Promise<{ headers: ApiResponseHeaders; body: Caption }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -78,19 +95,19 @@ export default class CaptionsApi { formData.append(fileName, fileBuffer, fileName); queryParams.body = formData; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'Caption', - '' - ) as Caption - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'Caption', + '' + ) as Caption, + }; + }); } /** @@ -102,6 +119,23 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt * @param language A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). */ public async get(videoId: string, language: string): Promise { + return this.getWithResponseHeaders(videoId, language).then( + (res) => res.body + ); + } + + /** + * Retrieve a caption for a video in a specific language. If the language is available, the caption is returned. Otherwise, you will get a error indicating the caption was not found. + +Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/captions). + * Retrieve a caption + * @param videoId The unique identifier for the video you want captions for. + * @param language A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + */ + public async getWithResponseHeaders( + videoId: string, + language: string + ): Promise<{ headers: ApiResponseHeaders; body: Caption }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -122,19 +156,19 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'Caption', - '' - ) as Caption - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'Caption', + '' + ) as Caption, + }; + }); } /** @@ -149,6 +183,25 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt language: string, captionsUpdatePayload: CaptionsUpdatePayload = {} ): Promise { + return this.updateWithResponseHeaders( + videoId, + language, + captionsUpdatePayload + ).then((res) => res.body); + } + + /** + * To have the captions on automatically, use this method to set default: true. + * Update a caption + * @param videoId The unique identifier for the video you want to have automatic captions for. + * @param language A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + * @param captionsUpdatePayload + */ + public async updateWithResponseHeaders( + videoId: string, + language: string, + captionsUpdatePayload: CaptionsUpdatePayload = {} + ): Promise<{ headers: ApiResponseHeaders; body: Caption }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -189,19 +242,19 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt queryParams.method = 'PATCH'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'Caption', - '' - ) as Caption - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'Caption', + '' + ) as Caption, + }; + }); } /** @@ -211,6 +264,21 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt * @param language A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). */ public async delete(videoId: string, language: string): Promise { + return this.deleteWithResponseHeaders(videoId, language).then( + (res) => res.body + ); + } + + /** + * Delete a caption in a specific language by by video id. + * Delete a caption + * @param videoId The unique identifier for the video you want to delete a caption from. + * @param language A valid language identifier using IETF language tags. You can use primary subtags like `en` (English), extended subtags like `fr-CA` (French, Canada), or region subtags like `zh-Hans-CN` (Simplified Chinese used in the PRC). - This parameter **only accepts dashes for separators**, for example `fr-CA`. If you use a different separator in your request, the API returns an error. - When the value in your request does not match any covered language, the API returns an error. - You can find the list of supported tags [here](https://docs.api.video/vod/add-captions#supported-caption-language-tags). + */ + public async deleteWithResponseHeaders( + videoId: string, + language: string + ): Promise<{ headers: ApiResponseHeaders; body: void }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -231,19 +299,19 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt queryParams.method = 'DELETE'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'void', - '' - ) as void - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'void', + '' + ) as void, + }; + }); } /** @@ -254,7 +322,23 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. */ - public async list({ + public async list(args: { + videoId: string; + currentPage?: number; + pageSize?: number; + }): Promise { + return this.listWithResponseHeaders(args).then((res) => res.body); + } + + /** + * Retrieve a list of available captions by video id. + * List video captions + * @param {Object} searchParams + * @param { string } searchParams.videoId The unique identifier for the video you want to retrieve a list of captions for. + * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 + * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. + */ + public async listWithResponseHeaders({ videoId, currentPage, pageSize, @@ -262,7 +346,7 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt videoId: string; currentPage?: number; pageSize?: number; - }): Promise { + }): Promise<{ headers: ApiResponseHeaders; body: CaptionsListResponse }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -295,18 +379,18 @@ Tutorials that use the [captions endpoint](https://api.video/blog/endpoints/capt queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'CaptionsListResponse', - '' - ) as CaptionsListResponse - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'CaptionsListResponse', + '' + ) as CaptionsListResponse, + }; + }); } } diff --git a/src/api/ChaptersApi.ts b/src/api/ChaptersApi.ts index 5f2b0d1..91dc450 100644 --- a/src/api/ChaptersApi.ts +++ b/src/api/ChaptersApi.ts @@ -14,7 +14,7 @@ import { createReadStream } from 'fs'; import { URLSearchParams } from 'url'; import FormData from 'form-data'; import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import Chapter from '../model/Chapter'; import ChaptersListResponse from '../model/ChaptersListResponse'; import { Readable } from 'stream'; @@ -42,6 +42,23 @@ export default class ChaptersApi { language: string, file: string | Readable | Buffer ): Promise { + return this.uploadWithResponseHeaders(videoId, language, file).then( + (res) => res.body + ); + } + + /** + * Upload a VTT file to add chapters to your video. Chapters help break the video into sections. Read our [tutorial](https://api.video/blog/tutorials/adding-chapters-to-your-videos/) for more details. + * Upload a chapter + * @param videoId The unique identifier for the video you want to upload a chapter for. + * @param language A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. + * @param file The VTT file describing the chapters you want to upload. + */ + public async uploadWithResponseHeaders( + videoId: string, + language: string, + file: string | Readable | Buffer + ): Promise<{ headers: ApiResponseHeaders; body: Chapter }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -77,19 +94,19 @@ export default class ChaptersApi { formData.append(fileName, fileBuffer, fileName); queryParams.body = formData; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'Chapter', - '' - ) as Chapter - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'Chapter', + '' + ) as Chapter, + }; + }); } /** @@ -99,6 +116,21 @@ export default class ChaptersApi { * @param language A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. */ public async get(videoId: string, language: string): Promise { + return this.getWithResponseHeaders(videoId, language).then( + (res) => res.body + ); + } + + /** + * Retrieve a chapter for by video id in a specific language. + * Retrieve a chapter + * @param videoId The unique identifier for the video you want to show a chapter for. + * @param language A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. + */ + public async getWithResponseHeaders( + videoId: string, + language: string + ): Promise<{ headers: ApiResponseHeaders; body: Chapter }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -119,19 +151,19 @@ export default class ChaptersApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'Chapter', - '' - ) as Chapter - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'Chapter', + '' + ) as Chapter, + }; + }); } /** @@ -141,6 +173,21 @@ export default class ChaptersApi { * @param language A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. */ public async delete(videoId: string, language: string): Promise { + return this.deleteWithResponseHeaders(videoId, language).then( + (res) => res.body + ); + } + + /** + * Delete a chapter in a specific language by providing the video ID for the video you want to delete the chapter from and the language the chapter is in. + * Delete a chapter + * @param videoId The unique identifier for the video you want to delete a chapter from. + * @param language A valid [BCP 47](https://github.com/libyal/libfwnt/wiki/Language-Code-identifiers) language representation. + */ + public async deleteWithResponseHeaders( + videoId: string, + language: string + ): Promise<{ headers: ApiResponseHeaders; body: void }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -161,19 +208,35 @@ export default class ChaptersApi { queryParams.method = 'DELETE'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'void', - '' - ) as void - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'void', + '' + ) as void, + }; + }); + } + + /** + * Retrieve a list of all chapters for by video id. + * List video chapters + * @param {Object} searchParams + * @param { string } searchParams.videoId The unique identifier for the video you want to retrieve a list of chapters for. + * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 + * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. + */ + public async list(args: { + videoId: string; + currentPage?: number; + pageSize?: number; + }): Promise { + return this.listWithResponseHeaders(args).then((res) => res.body); } /** @@ -184,7 +247,7 @@ export default class ChaptersApi { * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. */ - public async list({ + public async listWithResponseHeaders({ videoId, currentPage, pageSize, @@ -192,7 +255,7 @@ export default class ChaptersApi { videoId: string; currentPage?: number; pageSize?: number; - }): Promise { + }): Promise<{ headers: ApiResponseHeaders; body: ChaptersListResponse }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (videoId === null || videoId === undefined) { @@ -225,18 +288,18 @@ export default class ChaptersApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'ChaptersListResponse', - '' - ) as ChaptersListResponse - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'ChaptersListResponse', + '' + ) as ChaptersListResponse, + }; + }); } } diff --git a/src/api/LiveStreamsApi.ts b/src/api/LiveStreamsApi.ts index 1aca782..0764416 100644 --- a/src/api/LiveStreamsApi.ts +++ b/src/api/LiveStreamsApi.ts @@ -14,7 +14,7 @@ import { createReadStream } from 'fs'; import { URLSearchParams } from 'url'; import FormData from 'form-data'; import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import LiveStream from '../model/LiveStream'; import LiveStreamCreationPayload from '../model/LiveStreamCreationPayload'; import LiveStreamListResponse from '../model/LiveStreamListResponse'; @@ -40,6 +40,19 @@ export default class LiveStreamsApi { public async create( liveStreamCreationPayload: LiveStreamCreationPayload ): Promise { + return this.createWithResponseHeaders(liveStreamCreationPayload).then( + (res) => res.body + ); + } + + /** + * Creates a livestream object. + * Create live stream + * @param liveStreamCreationPayload + */ + public async createWithResponseHeaders( + liveStreamCreationPayload: LiveStreamCreationPayload + ): Promise<{ headers: ApiResponseHeaders; body: LiveStream }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if ( @@ -70,19 +83,19 @@ export default class LiveStreamsApi { queryParams.method = 'POST'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'LiveStream', - '' - ) as LiveStream - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'LiveStream', + '' + ) as LiveStream, + }; + }); } /** @@ -91,6 +104,17 @@ export default class LiveStreamsApi { * @param liveStreamId The unique ID for the live stream you want to watch. */ public async get(liveStreamId: string): Promise { + return this.getWithResponseHeaders(liveStreamId).then((res) => res.body); + } + + /** + * Get a livestream by id. + * Retrieve live stream + * @param liveStreamId The unique ID for the live stream you want to watch. + */ + public async getWithResponseHeaders( + liveStreamId: string + ): Promise<{ headers: ApiResponseHeaders; body: LiveStream }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (liveStreamId === null || liveStreamId === undefined) { @@ -108,19 +132,19 @@ export default class LiveStreamsApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'LiveStream', - '' - ) as LiveStream - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'LiveStream', + '' + ) as LiveStream, + }; + }); } /** @@ -133,6 +157,22 @@ export default class LiveStreamsApi { liveStreamId: string, liveStreamUpdatePayload: LiveStreamUpdatePayload = {} ): Promise { + return this.updateWithResponseHeaders( + liveStreamId, + liveStreamUpdatePayload + ).then((res) => res.body); + } + + /** + * Updates the livestream object. + * Update a live stream + * @param liveStreamId The unique ID for the live stream that you want to update information for such as player details. + * @param liveStreamUpdatePayload + */ + public async updateWithResponseHeaders( + liveStreamId: string, + liveStreamUpdatePayload: LiveStreamUpdatePayload = {} + ): Promise<{ headers: ApiResponseHeaders; body: LiveStream }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (liveStreamId === null || liveStreamId === undefined) { @@ -173,19 +213,19 @@ export default class LiveStreamsApi { queryParams.method = 'PATCH'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'LiveStream', - '' - ) as LiveStream - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'LiveStream', + '' + ) as LiveStream, + }; + }); } /** @@ -194,6 +234,17 @@ export default class LiveStreamsApi { * @param liveStreamId The unique ID for the live stream that you want to remove. */ public async delete(liveStreamId: string): Promise { + return this.deleteWithResponseHeaders(liveStreamId).then((res) => res.body); + } + + /** + * If you do not need a live stream any longer, you can send a request to delete it. All you need is the liveStreamId. + * Delete a live stream + * @param liveStreamId The unique ID for the live stream that you want to remove. + */ + public async deleteWithResponseHeaders( + liveStreamId: string + ): Promise<{ headers: ApiResponseHeaders; body: void }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (liveStreamId === null || liveStreamId === undefined) { @@ -211,19 +262,43 @@ export default class LiveStreamsApi { queryParams.method = 'DELETE'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'void', - '' - ) as void - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'void', + '' + ) as void, + }; + }); + } + + /** + * Get the list of livestreams on the workspace. + * List all live streams + * @param {Object} searchParams + * @param { string } searchParams.streamKey The unique stream key that allows you to stream videos. + * @param { string } searchParams.name You can filter live streams by their name or a part of their name. + * @param { 'name' | 'createdAt' | 'updatedAt' } searchParams.sortBy Enables you to sort live stream results. Allowed attributes: `name`, `createdAt`, `updatedAt`. `name` - the name of the live stream. `createdAt` - the time a live stream was created. `updatedAt` - the time a live stream was last updated. When using `createdAt` or `updatedAt`, the API sorts the results based on the ISO-8601 time format. + * @param { 'asc' | 'desc' } searchParams.sortOrder Allowed: asc, desc. Ascending for date and time means that earlier values precede later ones. Descending means that later values preced earlier ones. For title, it is 0-9 and A-Z ascending and Z-A, 9-0 descending. + * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 + * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. + */ + public async list( + args: { + streamKey?: string; + name?: string; + sortBy?: 'name' | 'createdAt' | 'updatedAt'; + sortOrder?: 'asc' | 'desc'; + currentPage?: number; + pageSize?: number; + } = {} + ): Promise { + return this.listWithResponseHeaders(args).then((res) => res.body); } /** @@ -237,7 +312,7 @@ export default class LiveStreamsApi { * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. */ - public async list({ + public async listWithResponseHeaders({ streamKey, name, sortBy, @@ -251,7 +326,10 @@ export default class LiveStreamsApi { sortOrder?: 'asc' | 'desc'; currentPage?: number; pageSize?: number; - } = {}): Promise { + } = {}): Promise<{ + headers: ApiResponseHeaders; + body: LiveStreamListResponse; + }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; // Path Params @@ -305,19 +383,19 @@ export default class LiveStreamsApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'LiveStreamListResponse', - '' - ) as LiveStreamListResponse - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'LiveStreamListResponse', + '' + ) as LiveStreamListResponse, + }; + }); } /** @@ -330,6 +408,21 @@ export default class LiveStreamsApi { liveStreamId: string, file: string | Readable | Buffer ): Promise { + return this.uploadThumbnailWithResponseHeaders(liveStreamId, file).then( + (res) => res.body + ); + } + + /** + * Upload the thumbnail for the livestream. + * Upload a thumbnail + * @param liveStreamId The unique ID for the live stream you want to upload. + * @param file The image to be added as a thumbnail. The mime type should be image/jpeg, image/png or image/webp. The max allowed size is 8 MiB. + */ + public async uploadThumbnailWithResponseHeaders( + liveStreamId: string, + file: string | Readable | Buffer + ): Promise<{ headers: ApiResponseHeaders; body: LiveStream }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (liveStreamId === null || liveStreamId === undefined) { @@ -362,19 +455,19 @@ export default class LiveStreamsApi { formData.append(fileName, fileBuffer, fileName); queryParams.body = formData; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'LiveStream', - '' - ) as LiveStream - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'LiveStream', + '' + ) as LiveStream, + }; + }); } /** @@ -383,6 +476,19 @@ export default class LiveStreamsApi { * @param liveStreamId The unique identifier of the live stream whose thumbnail you want to delete. */ public async deleteThumbnail(liveStreamId: string): Promise { + return this.deleteThumbnailWithResponseHeaders(liveStreamId).then( + (res) => res.body + ); + } + + /** + * Send the unique identifier for a live stream to delete its thumbnail. + * Delete a thumbnail + * @param liveStreamId The unique identifier of the live stream whose thumbnail you want to delete. + */ + public async deleteThumbnailWithResponseHeaders( + liveStreamId: string + ): Promise<{ headers: ApiResponseHeaders; body: LiveStream }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (liveStreamId === null || liveStreamId === undefined) { @@ -400,18 +506,18 @@ export default class LiveStreamsApi { queryParams.method = 'DELETE'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'LiveStream', - '' - ) as LiveStream - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'LiveStream', + '' + ) as LiveStream, + }; + }); } } diff --git a/src/api/PlayerThemesApi.ts b/src/api/PlayerThemesApi.ts index 91738ad..0693573 100644 --- a/src/api/PlayerThemesApi.ts +++ b/src/api/PlayerThemesApi.ts @@ -14,7 +14,7 @@ import { createReadStream } from 'fs'; import { URLSearchParams } from 'url'; import FormData from 'form-data'; import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import PlayerTheme from '../model/PlayerTheme'; import PlayerThemeCreationPayload from '../model/PlayerThemeCreationPayload'; import PlayerThemeUpdatePayload from '../model/PlayerThemeUpdatePayload'; @@ -40,6 +40,19 @@ export default class PlayerThemesApi { public async create( playerThemeCreationPayload: PlayerThemeCreationPayload = {} ): Promise { + return this.createWithResponseHeaders(playerThemeCreationPayload).then( + (res) => res.body + ); + } + + /** + * Create a player for your video, and customise it. + * Create a player + * @param playerThemeCreationPayload + */ + public async createWithResponseHeaders( + playerThemeCreationPayload: PlayerThemeCreationPayload = {} + ): Promise<{ headers: ApiResponseHeaders; body: PlayerTheme }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if ( @@ -70,19 +83,19 @@ export default class PlayerThemesApi { queryParams.method = 'POST'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'PlayerTheme', - '' - ) as PlayerTheme - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'PlayerTheme', + '' + ) as PlayerTheme, + }; + }); } /** @@ -91,6 +104,17 @@ export default class PlayerThemesApi { * @param playerId The unique identifier for the player you want to retrieve. */ public async get(playerId: string): Promise { + return this.getWithResponseHeaders(playerId).then((res) => res.body); + } + + /** + * Retreive a player theme by player id. + * Retrieve a player + * @param playerId The unique identifier for the player you want to retrieve. + */ + public async getWithResponseHeaders( + playerId: string + ): Promise<{ headers: ApiResponseHeaders; body: PlayerTheme }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (playerId === null || playerId === undefined) { @@ -105,19 +129,19 @@ export default class PlayerThemesApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'PlayerTheme', - '' - ) as PlayerTheme - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'PlayerTheme', + '' + ) as PlayerTheme, + }; + }); } /** @@ -130,6 +154,22 @@ export default class PlayerThemesApi { playerId: string, playerThemeUpdatePayload: PlayerThemeUpdatePayload = {} ): Promise { + return this.updateWithResponseHeaders( + playerId, + playerThemeUpdatePayload + ).then((res) => res.body); + } + + /** + * Use a player ID to update specific details for a player. NOTE: It may take up to 10 min before the new player configuration is available from our CDN. + * Update a player + * @param playerId The unique identifier for the player. + * @param playerThemeUpdatePayload + */ + public async updateWithResponseHeaders( + playerId: string, + playerThemeUpdatePayload: PlayerThemeUpdatePayload = {} + ): Promise<{ headers: ApiResponseHeaders; body: PlayerTheme }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (playerId === null || playerId === undefined) { @@ -167,19 +207,19 @@ export default class PlayerThemesApi { queryParams.method = 'PATCH'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'PlayerTheme', - '' - ) as PlayerTheme - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'PlayerTheme', + '' + ) as PlayerTheme, + }; + }); } /** @@ -188,6 +228,17 @@ export default class PlayerThemesApi { * @param playerId The unique identifier for the player you want to delete. */ public async delete(playerId: string): Promise { + return this.deleteWithResponseHeaders(playerId).then((res) => res.body); + } + + /** + * Delete a player if you no longer need it. You can delete any player that you have the player ID for. + * Delete a player + * @param playerId The unique identifier for the player you want to delete. + */ + public async deleteWithResponseHeaders( + playerId: string + ): Promise<{ headers: ApiResponseHeaders; body: void }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (playerId === null || playerId === undefined) { @@ -202,19 +253,39 @@ export default class PlayerThemesApi { queryParams.method = 'DELETE'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'void', - '' - ) as void - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'void', + '' + ) as void, + }; + }); + } + + /** + * Retrieve a list of all the player themes you created, as well as details about each one. + * List all player themes + * @param {Object} searchParams + * @param { 'name' | 'createdAt' | 'updatedAt' } searchParams.sortBy createdAt is the time the player was created. updatedAt is the time the player was last updated. The time is presented in ISO-8601 format. + * @param { 'asc' | 'desc' } searchParams.sortOrder Allowed: asc, desc. Ascending for date and time means that earlier values precede later ones. Descending means that later values preced earlier ones. + * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 + * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. + */ + public async list( + args: { + sortBy?: 'name' | 'createdAt' | 'updatedAt'; + sortOrder?: 'asc' | 'desc'; + currentPage?: number; + pageSize?: number; + } = {} + ): Promise { + return this.listWithResponseHeaders(args).then((res) => res.body); } /** @@ -226,7 +297,7 @@ export default class PlayerThemesApi { * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. */ - public async list({ + public async listWithResponseHeaders({ sortBy, sortOrder, currentPage, @@ -236,7 +307,10 @@ export default class PlayerThemesApi { sortOrder?: 'asc' | 'desc'; currentPage?: number; pageSize?: number; - } = {}): Promise { + } = {}): Promise<{ + headers: ApiResponseHeaders; + body: PlayerThemesListResponse; + }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; // Path Params @@ -278,19 +352,19 @@ export default class PlayerThemesApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'PlayerThemesListResponse', - '' - ) as PlayerThemesListResponse - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'PlayerThemesListResponse', + '' + ) as PlayerThemesListResponse, + }; + }); } /** @@ -305,6 +379,23 @@ export default class PlayerThemesApi { file: string | Readable | Buffer, link?: string ): Promise { + return this.uploadLogoWithResponseHeaders(playerId, file, link).then( + (res) => res.body + ); + } + + /** + * Upload an image file as a logo for your player. The image should fit within these constraints: - The image mime type must be `image/jpeg` or `image/png`. api.video recommends using `png` images with transparent background. - The image size should be a maximum of 200px width x 100px. - The file size should be a maximum of 100 KiB. + * Upload a logo + * @param playerId The unique identifier for the player. + * @param file The name of the file you want to use for your logo. + * @param link A public link that you want to advertise in your player. For example, you could add a link to your company. When a viewer clicks on your logo, they will be taken to this address. + */ + public async uploadLogoWithResponseHeaders( + playerId: string, + file: string | Readable | Buffer, + link?: string + ): Promise<{ headers: ApiResponseHeaders; body: PlayerTheme }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (playerId === null || playerId === undefined) { @@ -338,19 +429,19 @@ export default class PlayerThemesApi { } queryParams.body = formData; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'PlayerTheme', - '' - ) as PlayerTheme - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'PlayerTheme', + '' + ) as PlayerTheme, + }; + }); } /** @@ -359,6 +450,17 @@ export default class PlayerThemesApi { * @param playerId The unique identifier for the player. */ public async deleteLogo(playerId: string): Promise { + return this.deleteLogoWithResponseHeaders(playerId).then((res) => res.body); + } + + /** + * Delete the logo associated to a player. + * Delete logo + * @param playerId The unique identifier for the player. + */ + public async deleteLogoWithResponseHeaders( + playerId: string + ): Promise<{ headers: ApiResponseHeaders; body: void }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (playerId === null || playerId === undefined) { @@ -373,18 +475,18 @@ export default class PlayerThemesApi { queryParams.method = 'DELETE'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'void', - '' - ) as void - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'void', + '' + ) as void, + }; + }); } } diff --git a/src/api/UploadTokensApi.ts b/src/api/UploadTokensApi.ts index 2918bd7..ee8e6cf 100644 --- a/src/api/UploadTokensApi.ts +++ b/src/api/UploadTokensApi.ts @@ -11,7 +11,7 @@ import { URLSearchParams } from 'url'; import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import TokenCreationPayload from '../model/TokenCreationPayload'; import TokenListResponse from '../model/TokenListResponse'; import UploadToken from '../model/UploadToken'; @@ -34,6 +34,19 @@ export default class UploadTokensApi { public async createToken( tokenCreationPayload: TokenCreationPayload = {} ): Promise { + return this.createTokenWithResponseHeaders(tokenCreationPayload).then( + (res) => res.body + ); + } + + /** + * Generates an upload token that can be used to replace the API Key. More information can be found [here](https://docs.api.video/vod/delegated-upload-tokens) + * Generate an upload token + * @param tokenCreationPayload + */ + public async createTokenWithResponseHeaders( + tokenCreationPayload: TokenCreationPayload = {} + ): Promise<{ headers: ApiResponseHeaders; body: UploadToken }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (tokenCreationPayload === null || tokenCreationPayload === undefined) { @@ -61,19 +74,19 @@ export default class UploadTokensApi { queryParams.method = 'POST'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'UploadToken', - '' - ) as UploadToken - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'UploadToken', + '' + ) as UploadToken, + }; + }); } /** @@ -82,6 +95,19 @@ export default class UploadTokensApi { * @param uploadToken The unique identifier for the token you want information about. */ public async getToken(uploadToken: string): Promise { + return this.getTokenWithResponseHeaders(uploadToken).then( + (res) => res.body + ); + } + + /** + * Retrieve details about a specific upload token by id. + * Retrieve upload token + * @param uploadToken The unique identifier for the token you want information about. + */ + public async getTokenWithResponseHeaders( + uploadToken: string + ): Promise<{ headers: ApiResponseHeaders; body: UploadToken }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (uploadToken === null || uploadToken === undefined) { @@ -99,19 +125,19 @@ export default class UploadTokensApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'UploadToken', - '' - ) as UploadToken - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'UploadToken', + '' + ) as UploadToken, + }; + }); } /** @@ -120,6 +146,19 @@ export default class UploadTokensApi { * @param uploadToken The unique identifier for the upload token you want to delete. Deleting a token will make it so the token can no longer be used for authentication. */ public async deleteToken(uploadToken: string): Promise { + return this.deleteTokenWithResponseHeaders(uploadToken).then( + (res) => res.body + ); + } + + /** + * Delete an existing upload token. This is especially useful for tokens you may have created that do not expire. + * Delete an upload token + * @param uploadToken The unique identifier for the upload token you want to delete. Deleting a token will make it so the token can no longer be used for authentication. + */ + public async deleteTokenWithResponseHeaders( + uploadToken: string + ): Promise<{ headers: ApiResponseHeaders; body: void }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; if (uploadToken === null || uploadToken === undefined) { @@ -137,19 +176,39 @@ export default class UploadTokensApi { queryParams.method = 'DELETE'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'void', - '' - ) as void - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'void', + '' + ) as void, + }; + }); + } + + /** + * Retrieve a list of all currently active delegated tokens. + * List all active upload tokens + * @param {Object} searchParams + * @param { 'createdAt' | 'ttl' } searchParams.sortBy Allowed: createdAt, ttl. You can use these to sort by when a token was created, or how much longer the token will be active (ttl - time to live). Date and time is presented in ISO-8601 format. + * @param { 'asc' | 'desc' } searchParams.sortOrder Allowed: asc, desc. Ascending is 0-9 or A-Z. Descending is 9-0 or Z-A. + * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 + * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. + */ + public async list( + args: { + sortBy?: 'createdAt' | 'ttl'; + sortOrder?: 'asc' | 'desc'; + currentPage?: number; + pageSize?: number; + } = {} + ): Promise { + return this.listWithResponseHeaders(args).then((res) => res.body); } /** @@ -161,7 +220,7 @@ export default class UploadTokensApi { * @param { number } searchParams.currentPage Choose the number of search results to return per page. Minimum value: 1 * @param { number } searchParams.pageSize Results per page. Allowed values 1-100, default is 25. */ - public async list({ + public async listWithResponseHeaders({ sortBy, sortOrder, currentPage, @@ -171,7 +230,7 @@ export default class UploadTokensApi { sortOrder?: 'asc' | 'desc'; currentPage?: number; pageSize?: number; - } = {}): Promise { + } = {}): Promise<{ headers: ApiResponseHeaders; body: TokenListResponse }> { const queryParams: QueryOptions = {}; queryParams.headers = {}; // Path Params @@ -209,18 +268,18 @@ export default class UploadTokensApi { queryParams.method = 'GET'; - return this.httpClient - .call(localVarPath, queryParams) - .then( - (response) => - ObjectSerializer.deserialize( - ObjectSerializer.parse( - response.body, - response.headers['content-type'] - ), - 'TokenListResponse', - '' - ) as TokenListResponse - ); + return this.httpClient.call(localVarPath, queryParams).then((response) => { + return { + headers: response.headers, + body: ObjectSerializer.deserialize( + ObjectSerializer.parse( + response.body, + response.headers['content-type'] + ), + 'TokenListResponse', + '' + ) as TokenListResponse, + }; + }); } } diff --git a/src/api/VideosApi.ts b/src/api/VideosApi.ts index 5206408..70a8a02 100644 --- a/src/api/VideosApi.ts +++ b/src/api/VideosApi.ts @@ -14,7 +14,7 @@ import { existsSync, statSync, createReadStream } from 'fs'; import { URLSearchParams } from 'url'; import FormData from 'form-data'; import ObjectSerializer from '../ObjectSerializer'; -import HttpClient, { QueryOptions } from '../HttpClient'; +import HttpClient, { QueryOptions, ApiResponseHeaders } from '../HttpClient'; import ProgressiveSession from '../model/ProgressiveSession'; import Video from '../model/Video'; import VideoCreationPayload from '../model/VideoCreationPayload'; @@ -44,6 +44,19 @@ export default class VideosApi { public async create( videoCreationPayload: VideoCreationPayload ): Promise