box-node-sdk
Version:
Official SDK for Box Platform APIs
295 lines (292 loc) • 12.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrashedFilesManager = exports.DeleteTrashedFileByIdHeaders = exports.GetTrashedFileByIdHeaders = exports.RestoreFileFromTrashHeaders = exports.DeleteTrashedFileByIdOptionals = exports.GetTrashedFileByIdOptionals = exports.RestoreFileFromTrashOptionals = void 0;
exports.serializeRestoreFileFromTrashRequestBodyParentField = serializeRestoreFileFromTrashRequestBodyParentField;
exports.deserializeRestoreFileFromTrashRequestBodyParentField = deserializeRestoreFileFromTrashRequestBodyParentField;
exports.serializeRestoreFileFromTrashRequestBody = serializeRestoreFileFromTrashRequestBody;
exports.deserializeRestoreFileFromTrashRequestBody = deserializeRestoreFileFromTrashRequestBody;
const trashFileRestored_1 = require("../schemas/trashFileRestored");
const trashFile_1 = require("../schemas/trashFile");
const errors_1 = require("../box/errors");
const network_1 = require("../networking/network");
const fetchOptions_1 = require("../networking/fetchOptions");
const utils_1 = require("../internal/utils");
const utils_2 = require("../internal/utils");
const json_1 = require("../serialization/json");
const json_2 = require("../serialization/json");
class RestoreFileFromTrashOptionals {
requestBody = {};
queryParams = {};
headers = new RestoreFileFromTrashHeaders({});
cancellationToken = void 0;
constructor(fields) {
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;
}
}
}
exports.RestoreFileFromTrashOptionals = RestoreFileFromTrashOptionals;
class GetTrashedFileByIdOptionals {
queryParams = {};
headers = new GetTrashedFileByIdHeaders({});
cancellationToken = void 0;
constructor(fields) {
if (fields.queryParams !== undefined) {
this.queryParams = fields.queryParams;
}
if (fields.headers !== undefined) {
this.headers = fields.headers;
}
if (fields.cancellationToken !== undefined) {
this.cancellationToken = fields.cancellationToken;
}
}
}
exports.GetTrashedFileByIdOptionals = GetTrashedFileByIdOptionals;
class DeleteTrashedFileByIdOptionals {
headers = new DeleteTrashedFileByIdHeaders({});
cancellationToken = void 0;
constructor(fields) {
if (fields.headers !== undefined) {
this.headers = fields.headers;
}
if (fields.cancellationToken !== undefined) {
this.cancellationToken = fields.cancellationToken;
}
}
}
exports.DeleteTrashedFileByIdOptionals = DeleteTrashedFileByIdOptionals;
class RestoreFileFromTrashHeaders {
/**
* Extra headers that will be included in the HTTP request. */
extraHeaders = {};
constructor(fields) {
if (fields.extraHeaders !== undefined) {
this.extraHeaders = fields.extraHeaders;
}
}
}
exports.RestoreFileFromTrashHeaders = RestoreFileFromTrashHeaders;
class GetTrashedFileByIdHeaders {
/**
* Extra headers that will be included in the HTTP request. */
extraHeaders = {};
constructor(fields) {
if (fields.extraHeaders !== undefined) {
this.extraHeaders = fields.extraHeaders;
}
}
}
exports.GetTrashedFileByIdHeaders = GetTrashedFileByIdHeaders;
class DeleteTrashedFileByIdHeaders {
/**
* Extra headers that will be included in the HTTP request. */
extraHeaders = {};
constructor(fields) {
if (fields.extraHeaders !== undefined) {
this.extraHeaders = fields.extraHeaders;
}
}
}
exports.DeleteTrashedFileByIdHeaders = DeleteTrashedFileByIdHeaders;
class TrashedFilesManager {
auth;
networkSession = new network_1.NetworkSession({});
constructor(fields) {
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 = (0, utils_1.prepareParams)({
['fields']: queryParams.fields
? queryParams.fields.map(utils_2.toString).join(',')
: undefined,
});
const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/files/', (0, utils_2.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 {
...(0, trashFileRestored_1.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`](https://developer.box.com/reference/get-folders-id-trash) API.
*
* To list all items that have been moved to the trash, please
* use the [`GET /folders/trash/items`](https://developer.box.com/reference/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 = (0, utils_1.prepareParams)({
['fields']: queryParams.fields
? queryParams.fields.map(utils_2.toString).join(',')
: undefined,
});
const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/files/', (0, utils_2.toString)(fileId), '/trash'),
method: 'GET',
params: queryParamsMap,
headers: headersMap,
responseFormat: 'json',
auth: this.auth,
networkSession: this.networkSession,
cancellationToken: cancellationToken,
}));
return {
...(0, trashFile_1.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 = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/files/', (0, utils_2.toString)(fileId), '/trash'),
method: 'DELETE',
headers: headersMap,
responseFormat: 'no_content',
auth: this.auth,
networkSession: this.networkSession,
cancellationToken: cancellationToken,
}));
return void 0;
}
}
exports.TrashedFilesManager = TrashedFilesManager;
function serializeRestoreFileFromTrashRequestBodyParentField(val) {
return { ['id']: val.id };
}
function deserializeRestoreFileFromTrashRequestBodyParentField(val) {
if (!(0, json_2.sdIsMap)(val)) {
throw new errors_1.BoxSdkError({
message: 'Expecting a map for "RestoreFileFromTrashRequestBodyParentField"',
});
}
if (!(val.id == void 0) && !(0, json_1.sdIsString)(val.id)) {
throw new errors_1.BoxSdkError({
message: 'Expecting string for "id" of type "RestoreFileFromTrashRequestBodyParentField"',
});
}
const id = val.id == void 0 ? void 0 : val.id;
return { id: id };
}
function serializeRestoreFileFromTrashRequestBody(val) {
return {
['name']: val.name,
['parent']: val.parent == void 0
? val.parent
: serializeRestoreFileFromTrashRequestBodyParentField(val.parent),
};
}
function deserializeRestoreFileFromTrashRequestBody(val) {
if (!(0, json_2.sdIsMap)(val)) {
throw new errors_1.BoxSdkError({
message: 'Expecting a map for "RestoreFileFromTrashRequestBody"',
});
}
if (!(val.name == void 0) && !(0, json_1.sdIsString)(val.name)) {
throw new errors_1.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.js.map