tsonik
Version:
A TypeScript client library for the Iconik API based on Swagger documentation
92 lines • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormatResource = void 0;
const base_1 = require("./base");
const utils_1 = require("../utils");
/**
* Format resource for managing formats in Iconik
*/
class FormatResource extends base_1.BaseResource {
constructor(client) {
super(client, '/API/files/v1');
}
/**
* Get all formats for a specific asset
*
* @param assetId - The ID of the asset
* @param params - Optional parameters for the request
* @returns Promise with the response containing asset formats
*/
async getAssetFormats(assetId, params) {
if (!assetId || assetId.trim() === '') {
throw new Error('Asset ID is required');
}
const config = Object.keys((0, utils_1.cleanParams)(params)).length > 0 ? { params: (0, utils_1.cleanParams)(params) } : undefined;
return this.client.get(`${this.basePath}/assets/${assetId}/formats/`, config);
}
/**
* Get a specific format for an asset
*
* @param assetId - The ID of the asset
* @param formatId - The ID of the format to retrieve
* @returns Promise with the response containing the format
*/
async getAssetFormat(assetId, formatId) {
if (!assetId || assetId.trim() === '') {
throw new Error('Asset ID is required');
}
if (!formatId || formatId.trim() === '') {
throw new Error('Format ID is required');
}
return this.client.get(`${this.basePath}/assets/${assetId}/formats/${formatId}/`);
}
/**
* Update an existing format for an asset
*
* @param assetId - The ID of the asset
* @param formatId - The ID of the format to update
* @param formatData - The format data to update
* @returns Promise with the response containing the updated format
*/
async updateAssetFormat(assetId, formatId, formatData) {
if (!assetId || assetId.trim() === '') {
throw new Error('Asset ID is required');
}
if (!formatId || formatId.trim() === '') {
throw new Error('Format ID is required');
}
return this.client.patch(`${this.basePath}/assets/${assetId}/formats/${formatId}/`, formatData);
}
/**
* Replace an existing format for an asset (complete replacement)
*
* @param assetId - The ID of the asset
* @param formatId - The ID of the format to replace
* @param formatData - The format data to replace with
* @returns Promise with the response containing the replaced format
*/
async replaceAssetFormat(assetId, formatId, formatData) {
if (!assetId || assetId.trim() === '') {
throw new Error('Asset ID is required');
}
if (!formatId || formatId.trim() === '') {
throw new Error('Format ID is required');
}
return this.client.put(`${this.basePath}/assets/${assetId}/formats/${formatId}/`, formatData);
}
/**
* Create a new format and associate it to an asset
*
* @param assetId - The ID of the asset to associate the format with
* @param formatData - The format data to create
* @returns Promise with the response containing the created format
*/
async createAssetFormat(assetId, formatData) {
if (!assetId || assetId.trim() === '') {
throw new Error('Asset ID is required');
}
return this.client.post(`${this.basePath}/assets/${assetId}/formats/`, formatData);
}
}
exports.FormatResource = FormatResource;
//# sourceMappingURL=formats.js.map