@zezosoft/zezo-transcoder-api-client
Version:
The official TypeScript SDK for Zezo Transcoder API. Easily integrate Zezo Transcoder into your applications with a powerful, developer-friendly package for video transcoding.
266 lines (257 loc) • 10.1 kB
TypeScript
import * as axios from 'axios';
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
declare class BaseService {
protected client: AxiosInstance;
constructor(options: IOptions);
protected request(config: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
}
interface IPopulate {
path: string;
select?: string[];
populate?: IPopulate[];
}
interface IPaginatedResponse<T> {
docs: T[];
totalDocs: number;
offset: number;
limit: number;
totalPages: number;
page: number;
pagingCounter: number;
hasPrevPage: boolean;
hasNextPage: boolean;
prevPage: null | number;
nextPage: null | number;
}
interface ICreateS3Storage {
bucketName: string;
region: string;
accessKeyId: string;
secretAccessKey: string;
provider: 'aws' | 'digitalOcean' | 'other';
for: 'input' | 'output';
}
interface IUpdateS3Storage extends ICreateS3Storage {
}
interface IGetListStorage {
page?: number;
limit?: number;
order?: 'asc' | 'desc';
sortBy?: string;
id?: string;
q?: string;
select?: string;
filters?: object;
populate?: IPopulate[];
}
interface IS3Storage {
_id: string;
bucketName: string;
region: string;
provider: "aws" | "digitalOcean" | "other";
createdBy: string;
for: "input" | "output";
createdAt: string;
updatedAt: string;
}
declare class StorageService extends BaseService {
constructor(options: IOptions);
/**
* Creates a new S3 storage configuration for the transcoder.
*
* @param payload - The S3 storage configuration object
* @param payload.bucketName - The name of the S3 bucket
* @param payload.region - The AWS region where the bucket is located
* @param payload.accessKeyId - The AWS access key ID for authentication
* @param payload.secretAccessKey - The AWS secret access key for authentication
* @param payload.provider - The storage provider type ('aws', 'digitalOcean', or 'other')
* @param payload.for - Whether this storage is for 'input' or 'output' files
*
* @returns Promise that resolves to an AxiosResponse containing the storage ID
*
* @throws {AxiosError} When the API request fails
*/
create(payload: ICreateS3Storage): Promise<AxiosResponse<{
id: string;
}>>;
/**
* Retrieves a paginated list of storage configurations.
*
* @param query - Optional query parameters for filtering and pagination
* @param query.page - Page number for pagination (default: 1)
* @param query.limit - Number of items per page (default: 10)
* @param query.order - Sort order ('asc' or 'desc')
* @param query.sortBy - Field to sort by
* @param query.id - Filter by specific storage ID
* @param query.q - Search query string
* @param query.select - Fields to select in the response
* @param query.filters - Additional filter criteria
* @param query.populate - Fields to populate with related data
*
* @returns Promise that resolves to a paginated response containing storage configurations
*
* @throws {AxiosError} When the API request fails
*/
getList(query?: IGetListStorage): Promise<AxiosResponse<IPaginatedResponse<IS3Storage>>>;
/**
* Deletes a storage configuration by ID.
*
* @param id - The unique identifier of the storage configuration to delete
*
* @returns Promise that resolves to an AxiosResponse containing the deleted storage ID
*
* @throws {AxiosError} When the API request fails or storage ID is not found
*/
delete(id: string): Promise<AxiosResponse<{
id: string;
}>>;
/**
* Updates an existing storage configuration.
*
* @param id - The unique identifier of the storage configuration to update
* @param payload - The updated storage configuration data
* @param payload.bucketName - The name of the S3 bucket
* @param payload.region - The AWS region where the bucket is located
* @param payload.accessKeyId - The AWS access key ID for authentication
* @param payload.secretAccessKey - The AWS secret access key for authentication
* @param payload.provider - The storage provider type ('aws', 'digitalOcean', or 'other')
* @param payload.for - Whether this storage is for 'input' or 'output' files
*
* @returns Promise that resolves to an AxiosResponse containing the updated storage ID
*
* @throws {AxiosError} When the API request fails or storage ID is not found
*/
update(id: string, payload: IUpdateS3Storage): Promise<AxiosResponse<{
id: string;
}>>;
}
type IJobResolution = "144p" | "240p" | "360p" | "480p" | "720p" | "1080p" | "2160p";
type IJobStatus = "submitted" | "processing" | "completed" | "failed" | "cancelled" | "queued" | "paused";
type IJobStorage = "s3Compatible";
type IJobConvertTo = "HLS";
type IJobInputType = "OPEN_URL" | "S3STORAGE";
interface IChildJob {
_id?: string;
convert_to: IJobConvertTo;
job_id: string;
resolution: IJobResolution;
status: IJobStatus;
progress: number;
process_id: string;
upload_to_storage_status: "none" | "uploading" | "success" | "failed" | "cancelled";
upload_to_storage_progress: number;
input_download_progress: number;
input_download_status?: "success" | "failed" | "downloading" | "none" | "cancelled";
error_message: string;
error: string;
}
interface ITranscodingJob {
_id: string;
name: string;
input_type: IJobInputType;
input_url_or_key: string;
input_storage_id?: string;
resolutions: IJobResolution[];
convert_to: IJobConvertTo;
output_storage: IJobStorage;
output_storage_id: string;
take_screenshot?: {
status: boolean;
time: number;
width?: number;
height?: number;
};
codec?: "h264" | "h265";
status?: IJobStatus;
duration?: number;
output_location_key?: string;
main_progress?: number;
upload_acl?: "private" | "public-read";
createdBy: string;
createdAt: Date;
updatedAt: Date;
child_jobs: IChildJob[];
}
interface ICreateTranscodingJob {
name: string;
input_type: IJobInputType;
input_url_or_key: string;
input_storage_id?: string;
resolutions: IJobResolution[];
convert_to: IJobConvertTo;
output_storage: IJobStorage;
output_storage_id: string;
take_screenshot?: {
status: boolean;
time: number;
width?: number;
height?: number;
};
codec?: "h264" | "h265";
upload_acl?: "private" | "public-read";
}
interface IGetListTranscodingJob {
page?: number;
limit?: number;
order?: "asc" | "desc";
sortBy?: string;
id?: string;
q?: string;
select?: string;
filters?: object;
populate?: IPopulate[];
}
interface ICreateTranscodingJobResponse {
job_id: string;
output_location: string;
}
declare class TranscodingService extends BaseService {
constructor(options: IOptions);
/**
* Creates a new transcoding job
* @param payload - The transcoding job configuration data
* @param payload.name - The name of the transcoding job
* @param payload.input_type - The input type ('S3STORAGE' only - 'OPEN_URL' coming in future)
* @param payload.input_url_or_key - The input URL or S3 key for the video file
* @param payload.input_storage_id - The storage ID for S3 input files (optional)
* @param payload.resolutions - Array of target resolutions ('144p', '240p', '360p', '480p', '720p', '1080p', '2160p')
* @param payload.convert_to - The output format ('HLS' only - 'MP4' and 'IMAGES' coming in future)
* @param payload.output_storage - The output storage type ('s3Compatible')
* @param payload.output_storage_id - The storage configuration ID for output files
* @param payload.take_screenshot - Screenshot configuration with status, time, width, and height (optional)
* @param payload.codec - The video codec ('h264' or 'h265') (optional)
* @param payload.upload_acl - The ACL for uploaded files ('private' or 'public-read') (optional)
* @returns Promise resolving to the created job ID
*/
create(payload: ICreateTranscodingJob): Promise<AxiosResponse<ICreateTranscodingJobResponse>>;
/**
* Retrieves a paginated list of transcoding jobs
* @param query - Optional query parameters for filtering and pagination
* @param query.page - Page number for pagination (default: 1) (optional)
* @param query.limit - Number of items per page (default: 10) (optional)
* @param query.order - Sort order ('asc' or 'desc') (optional)
* @param query.sortBy - Field to sort by (optional)
* @param query.id - Filter by specific job ID (optional)
* @param query.q - Search query string (optional)
* @param query.select - Fields to select in the response (optional)
* @param query.filters - Additional filter criteria (optional)
* @param query.populate - Fields to populate with related data (optional)
* @returns Promise resolving to paginated list of transcoding jobs
*/
getList(query?: IGetListTranscodingJob): Promise<AxiosResponse<IPaginatedResponse<ITranscodingJob>>>;
}
interface IOptions {
apiKey: string;
headers?: Record<string, string>;
}
declare class ZezoTranscoder {
storage: StorageService;
transcoding: TranscodingService;
/**
* Constructor for ZezoTranscoder class.
* @param {IOptions} options an object containing the API key and optionally
* custom headers for requests.
*/
constructor(options: IOptions);
}
export { type IChildJob, type ICreateS3Storage, type ICreateTranscodingJob, type ICreateTranscodingJobResponse, type IGetListStorage, type IGetListTranscodingJob, type IJobConvertTo, type IJobInputType, type IJobResolution, type IJobStatus, type IJobStorage, type IOptions, type IPaginatedResponse, type IPopulate, type IS3Storage, type ITranscodingJob, type IUpdateS3Storage, ZezoTranscoder };