UNPKG

tsonik

Version:

A TypeScript client library for the Iconik API based on Swagger documentation

60 lines 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileResource = void 0; const base_1 = require("./base"); const utils_1 = require("../utils"); /** * File resource for managing files in Iconik */ class FileResource extends base_1.BaseResource { constructor(client) { super(client, '/API/files/v1'); } /** * Get all files for an asset * * @param assetId - The ID of the asset * @param options - Optional parameters for the request * @returns Promise with the response containing asset files */ async getAssetFiles(assetId, options) { if (!assetId || assetId.trim() === '') { throw new Error('Asset ID is required'); } const config = Object.keys((0, utils_1.cleanParams)(options)).length > 0 ? { params: (0, utils_1.cleanParams)(options) } : undefined; return this.client.get(`${this.basePath}/assets/${assetId}/files/`, config); } /** * Get a specific file for an asset by file ID * * @param assetId - The ID of the asset * @param fileId - The ID of the file to retrieve * @param options - Optional parameters for the request * @returns Promise with the response containing the file */ async getAssetFile(assetId, fileId, options) { if (!assetId || assetId.trim() === '') { throw new Error('Asset ID is required'); } if (!fileId || fileId.trim() === '') { throw new Error('File ID is required'); } const config = Object.keys((0, utils_1.cleanParams)(options)).length > 0 ? { params: (0, utils_1.cleanParams)(options) } : undefined; return this.client.get(`${this.basePath}/assets/${assetId}/files/${fileId}/`, config); } /** * Create a new file and associate it to an asset * * @param assetId - The ID of the asset to associate the file with * @param fileData - The file data to create * @returns Promise with the response containing the created file */ async createAssetFile(assetId, fileData) { if (!assetId || assetId.trim() === '') { throw new Error('Asset ID is required'); } return this.client.post(`${this.basePath}/assets/${assetId}/files/`, fileData); } } exports.FileResource = FileResource; //# sourceMappingURL=files.js.map