UNPKG

box-typescript-sdk-gen

Version:
280 lines (277 loc) 11 kB
import { deserializeTrashFileRestored } from '../schemas/trashFileRestored.generated.js'; import { deserializeTrashFile } from '../schemas/trashFile.generated.js'; import { BoxSdkError } from '../box/errors.js'; import { NetworkSession } from '../networking/network.generated.js'; import { FetchOptions } from '../networking/fetchOptions.generated.js'; import { prepareParams } from '../internal/utils.js'; import { toString } from '../internal/utils.js'; import { sdIsString } from '../serialization/json.js'; import { sdIsMap } from '../serialization/json.js'; export class RestoreFileFromTrashOptionals { constructor(fields) { this.requestBody = {}; this.queryParams = {}; this.headers = new RestoreFileFromTrashHeaders({}); this.cancellationToken = void 0; if (fields.requestBody !== undefined) { this.requestBody = fields.requestBody; } if (fields.queryParams !== undefined) { this.queryParams = fields.queryParams; } if (fields.headers !== undefined) { this.headers = fields.headers; } if (fields.cancellationToken !== undefined) { this.cancellationToken = fields.cancellationToken; } } } export class GetTrashedFileByIdOptionals { constructor(fields) { this.queryParams = {}; this.headers = new GetTrashedFileByIdHeaders({}); this.cancellationToken = void 0; if (fields.queryParams !== undefined) { this.queryParams = fields.queryParams; } if (fields.headers !== undefined) { this.headers = fields.headers; } if (fields.cancellationToken !== undefined) { this.cancellationToken = fields.cancellationToken; } } } export class DeleteTrashedFileByIdOptionals { constructor(fields) { this.headers = new DeleteTrashedFileByIdHeaders({}); this.cancellationToken = void 0; if (fields.headers !== undefined) { this.headers = fields.headers; } if (fields.cancellationToken !== undefined) { this.cancellationToken = fields.cancellationToken; } } } export class RestoreFileFromTrashHeaders { constructor(fields) { /** * Extra headers that will be included in the HTTP request. */ this.extraHeaders = {}; if (fields.extraHeaders !== undefined) { this.extraHeaders = fields.extraHeaders; } } } export class GetTrashedFileByIdHeaders { constructor(fields) { /** * Extra headers that will be included in the HTTP request. */ this.extraHeaders = {}; if (fields.extraHeaders !== undefined) { this.extraHeaders = fields.extraHeaders; } } } export class DeleteTrashedFileByIdHeaders { constructor(fields) { /** * Extra headers that will be included in the HTTP request. */ this.extraHeaders = {}; if (fields.extraHeaders !== undefined) { this.extraHeaders = fields.extraHeaders; } } } export class TrashedFilesManager { constructor(fields) { this.networkSession = new NetworkSession({}); if (fields.auth !== undefined) { this.auth = fields.auth; } if (fields.networkSession !== undefined) { this.networkSession = fields.networkSession; } } /** * Restores a file that has been moved to the trash. * * An optional new parent ID can be provided to restore the file to in case the * original folder has been deleted. * @param {string} fileId The unique identifier that represents a file. The ID for any file can be determined by visiting a file in the web application and copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the `file_id` is `123`. Example: "12345" * @param {RestoreFileFromTrashOptionalsInput} optionalsInput * @returns {Promise<TrashFileRestored>} */ async restoreFileFromTrash(fileId, optionalsInput = {}) { const optionals = new RestoreFileFromTrashOptionals({ requestBody: optionalsInput.requestBody, queryParams: optionalsInput.queryParams, headers: optionalsInput.headers, cancellationToken: optionalsInput.cancellationToken, }); const requestBody = optionals.requestBody; const queryParams = optionals.queryParams; const headers = optionals.headers; const cancellationToken = optionals.cancellationToken; const queryParamsMap = prepareParams({ ['fields']: queryParams.fields ? queryParams.fields.map(toString).join(',') : undefined, }); const headersMap = prepareParams({ ...{}, ...headers.extraHeaders }); const response = await this.networkSession.networkClient.fetch(new FetchOptions({ url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/files/', toString(fileId)), method: 'POST', params: queryParamsMap, headers: headersMap, data: serializeRestoreFileFromTrashRequestBody(requestBody), contentType: 'application/json', responseFormat: 'json', auth: this.auth, networkSession: this.networkSession, cancellationToken: cancellationToken, })); return { ...deserializeTrashFileRestored(response.data), rawData: response.data, }; } /** * Retrieves a file that has been moved to the trash. * * Please note that only if the file itself has been moved to the * trash can it be retrieved with this API call. If instead one of * its parent folders was moved to the trash, only that folder * can be inspected using the * [`GET /folders/:id/trash`](e://get_folders_id_trash) API. * * To list all items that have been moved to the trash, please * use the [`GET /folders/trash/items`](e://get-folders-trash-items/) * API. * @param {string} fileId The unique identifier that represents a file. The ID for any file can be determined by visiting a file in the web application and copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the `file_id` is `123`. Example: "12345" * @param {GetTrashedFileByIdOptionalsInput} optionalsInput * @returns {Promise<TrashFile>} */ async getTrashedFileById(fileId, optionalsInput = {}) { const optionals = new GetTrashedFileByIdOptionals({ queryParams: optionalsInput.queryParams, headers: optionalsInput.headers, cancellationToken: optionalsInput.cancellationToken, }); const queryParams = optionals.queryParams; const headers = optionals.headers; const cancellationToken = optionals.cancellationToken; const queryParamsMap = prepareParams({ ['fields']: queryParams.fields ? queryParams.fields.map(toString).join(',') : undefined, }); const headersMap = prepareParams({ ...{}, ...headers.extraHeaders }); const response = await this.networkSession.networkClient.fetch(new FetchOptions({ url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/files/', toString(fileId), '/trash'), method: 'GET', params: queryParamsMap, headers: headersMap, responseFormat: 'json', auth: this.auth, networkSession: this.networkSession, cancellationToken: cancellationToken, })); return { ...deserializeTrashFile(response.data), rawData: response.data, }; } /** * Permanently deletes a file that is in the trash. * This action cannot be undone. * @param {string} fileId The unique identifier that represents a file. The ID for any file can be determined by visiting a file in the web application and copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the `file_id` is `123`. Example: "12345" * @param {DeleteTrashedFileByIdOptionalsInput} optionalsInput * @returns {Promise<undefined>} */ async deleteTrashedFileById(fileId, optionalsInput = {}) { const optionals = new DeleteTrashedFileByIdOptionals({ headers: optionalsInput.headers, cancellationToken: optionalsInput.cancellationToken, }); const headers = optionals.headers; const cancellationToken = optionals.cancellationToken; const headersMap = prepareParams({ ...{}, ...headers.extraHeaders }); const response = await this.networkSession.networkClient.fetch(new FetchOptions({ url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/files/', toString(fileId), '/trash'), method: 'DELETE', headers: headersMap, responseFormat: 'no_content', auth: this.auth, networkSession: this.networkSession, cancellationToken: cancellationToken, })); return void 0; } } export function serializeRestoreFileFromTrashRequestBodyParentField(val) { return { ['id']: val.id }; } export function deserializeRestoreFileFromTrashRequestBodyParentField(val) { if (!sdIsMap(val)) { throw new BoxSdkError({ message: 'Expecting a map for "RestoreFileFromTrashRequestBodyParentField"', }); } if (!(val.id == void 0) && !sdIsString(val.id)) { throw new BoxSdkError({ message: 'Expecting string for "id" of type "RestoreFileFromTrashRequestBodyParentField"', }); } const id = val.id == void 0 ? void 0 : val.id; return { id: id }; } export function serializeRestoreFileFromTrashRequestBody(val) { return { ['name']: val.name, ['parent']: val.parent == void 0 ? val.parent : serializeRestoreFileFromTrashRequestBodyParentField(val.parent), }; } export function deserializeRestoreFileFromTrashRequestBody(val) { if (!sdIsMap(val)) { throw new BoxSdkError({ message: 'Expecting a map for "RestoreFileFromTrashRequestBody"', }); } if (!(val.name == void 0) && !sdIsString(val.name)) { throw new BoxSdkError({ message: 'Expecting string for "name" of type "RestoreFileFromTrashRequestBody"', }); } const name = val.name == void 0 ? void 0 : val.name; const parent = val.parent == void 0 ? void 0 : deserializeRestoreFileFromTrashRequestBodyParentField(val.parent); return { name: name, parent: parent, }; } //# sourceMappingURL=trashedFiles.generated.js.map