metadata-based-explorer1
Version:
Box UI Elements
691 lines (588 loc) • 16.8 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
*
* @file Main entry point for the box api
* @author Box
*/
import Cache from '../utils/Cache';
import ChunkedUploadAPI from './uploads/MultiputUpload';
import PlainUploadAPI from './uploads/PlainUpload';
import FolderAPI from './Folder';
import FileAPI from './File';
import WebLinkAPI from './WebLink';
import SearchAPI from './Search';
import RecentsAPI from './Recents';
import VersionsAPI from './Versions';
import CommentsAPI from './Comments';
import TasksAPI from './tasks/Tasks';
import TaskAssignmentsAPI from './tasks/TaskAssignments';
import TasksNewAPI from './tasks/TasksNew';
import TaskCollaboratorsAPI from './tasks/TaskCollaborators';
import TaskLinksAPI from './tasks/TaskLinks';
import FileAccessStatsAPI from './FileAccessStats';
import UsersAPI from './Users';
import MetadataAPI from './Metadata';
import FileCollaboratorsAPI from './FileCollaborators';
import FeedAPI from './Feed';
import AppIntegrationsAPI from './AppIntegrations';
import OpenWithAPI from './OpenWith';
import MetadataQueryAPI from './MetadataQuery';
import BoxEditAPI from './box-edit';
import { DEFAULT_HOSTNAME_API, DEFAULT_HOSTNAME_UPLOAD, TYPE_FOLDER, TYPE_FILE, TYPE_WEBLINK } from '../constants';
var APIFactory =
/*#__PURE__*/
function () {
/**
* @property {*}
*/
/**
* @property {FileAPI}
*/
/**
* @property {WebLink}
*/
/**
* @property {FolderAPI}
*/
/**
* @property {PlainUploadAPI}
*/
/**
* @property {ChunkedUploadAPI}
*/
/**
* @property {SearchAPI}
*/
/**
* @property {RecentsAPI}
*/
/**
* @property {VersionsAPI}
*/
/**
* @property {CommentsAPI}
*/
/**
* @property {TasksAPI}
*/
/**
* @property {TaskAssignmentsAPI}
*/
/**
* @property {TasksNewAPI}
*/
/**
* @property {TaskCollaboratorsAPI}
*/
/**
* @property {TaskLinksAPI}
*/
/*
* @property {FileAccessStatsAPI}
*/
/*
* @property {UsersAPI}
*/
/*
* @property {MetadataAPI}
*/
/**
* @property {FileCollaboratorsAPI}
*/
/**
* @property {FeedAPI}
*/
/**
* @property {OpenWithAPI}
*/
/**
* @property {AppIntegrationsAPI}
*/
/**
* @property {MetadataQueryAPI}
*/
/** @property {BoxEditAPI}
*
*/
/**
* [constructor]
*
* @param {Object} options
* @param {string} options.id - item id
* @param {string|function} options.token - Auth token
* @param {string} [options.sharedLink] - Shared link
* @param {string} [options.sharedLinkPassword] - Shared link password
* @param {string} [options.apiHost] - Api host
* @param {string} [options.uploadHost] - Upload host name
* @return {API} Api instance
*/
function APIFactory(options) {
_classCallCheck(this, APIFactory);
this.options = _extends({}, options, {
apiHost: options.apiHost || DEFAULT_HOSTNAME_API,
uploadHost: options.uploadHost || DEFAULT_HOSTNAME_UPLOAD,
cache: options.cache || new Cache(),
language: options.language
});
}
/**
* [destructor]
*
* @param {boolean} destroyCache - true to destroy cache
* @return {void}
*/
_createClass(APIFactory, [{
key: "destroy",
value: function destroy() {
var destroyCache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (this.fileAPI) {
this.fileAPI.destroy();
delete this.fileAPI;
}
if (this.weblinkAPI) {
this.weblinkAPI.destroy();
delete this.weblinkAPI;
}
if (this.plainUploadAPI) {
this.plainUploadAPI.destroy();
delete this.plainUploadAPI;
}
if (this.chunkedUploadAPI) {
this.chunkedUploadAPI.destroy();
delete this.chunkedUploadAPI;
}
if (this.folderAPI) {
this.folderAPI.destroy();
delete this.folderAPI;
}
if (this.searchAPI) {
this.searchAPI.destroy();
delete this.searchAPI;
}
if (this.recentsAPI) {
this.recentsAPI.destroy();
delete this.recentsAPI;
}
if (this.versionsAPI) {
this.versionsAPI.destroy();
delete this.versionsAPI;
}
if (this.fileAccessStatsAPI) {
this.fileAccessStatsAPI.destroy();
delete this.fileAccessStatsAPI;
}
if (this.tasksAPI) {
this.tasksAPI.destroy();
delete this.tasksAPI;
}
if (this.tasksNewAPI) {
this.tasksNewAPI.destroy();
delete this.tasksNewAPI;
}
if (this.taskCollaboratorsAPI) {
this.taskCollaboratorsAPI.destroy();
delete this.taskCollaboratorsAPI;
}
if (this.taskLinksAPI) {
this.taskLinksAPI.destroy();
delete this.taskLinksAPI;
}
if (this.commentsAPI) {
this.commentsAPI.destroy();
delete this.commentsAPI;
}
if (this.usersAPI) {
this.usersAPI.destroy();
delete this.usersAPI;
}
if (this.metadataAPI) {
this.metadataAPI.destroy();
delete this.metadataAPI;
}
if (this.fileCollaboratorsAPI) {
this.fileCollaboratorsAPI.destroy();
delete this.fileCollaboratorsAPI;
}
if (this.appIntegrationsAPI) {
this.appIntegrationsAPI.destroy();
delete this.appIntegrationsAPI;
}
if (this.metadataQueryAPI) {
this.metadataQueryAPI.destroy();
delete this.metadataQueryAPI;
}
if (this.openWithAPI) {
this.openWithAPI.destroy();
delete this.openWithAPI;
}
if (destroyCache) {
this.options.cache = new Cache();
}
}
/**
* Gets the cache instance
*
* @return {Cache} cache instance
*/
}, {
key: "getCache",
value: function getCache() {
return this.options.cache;
}
/**
* Returns the API based on type of item
*
* @private
* @param {String} type - item type
* @return {ItemAPI} api
*/
}, {
key: "getAPI",
value: function getAPI(type) {
var api;
switch (type) {
case TYPE_FOLDER:
api = this.getFolderAPI();
break;
case TYPE_FILE:
api = this.getFileAPI();
break;
case TYPE_WEBLINK:
api = this.getWebLinkAPI();
break;
default:
throw new Error('Unknown Type!');
}
return api;
}
/**
* API for file
*
* @return {FileAPI} FileAPI instance
*/
}, {
key: "getFileAPI",
value: function getFileAPI() {
var shouldDestroy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (shouldDestroy) {
this.destroy();
}
this.fileAPI = new FileAPI(this.options);
return this.fileAPI;
}
/**
* API for web links
*
* @return {WebLinkAPI} WebLinkAPI instance
*/
}, {
key: "getWebLinkAPI",
value: function getWebLinkAPI() {
this.destroy();
this.weblinkAPI = new WebLinkAPI(this.options);
return this.weblinkAPI;
}
/**
* API for plain uploads
*
* @return {UploadAPI} UploadAPI instance
*/
}, {
key: "getPlainUploadAPI",
value: function getPlainUploadAPI() {
this.destroy();
this.plainUploadAPI = new PlainUploadAPI(this.options);
return this.plainUploadAPI;
}
/**
* API for chunked uploads
*
* @return {UploadAPI} UploadAPI instance
*/
}, {
key: "getChunkedUploadAPI",
value: function getChunkedUploadAPI() {
this.destroy();
this.chunkedUploadAPI = new ChunkedUploadAPI(this.options);
return this.chunkedUploadAPI;
}
/**
* API for folder
*
* @return {FolderAPI} FolderAPI instance
*/
}, {
key: "getFolderAPI",
value: function getFolderAPI() {
this.destroy();
this.folderAPI = new FolderAPI(this.options);
return this.folderAPI;
}
/**
* API for search
*
* @return {SearchAPI} SearchAPI instance
*/
}, {
key: "getSearchAPI",
value: function getSearchAPI() {
this.destroy();
this.searchAPI = new SearchAPI(this.options);
return this.searchAPI;
}
/**
* API for recents
*
* @return {RecentsAPI} RecentsAPI instance
*/
}, {
key: "getRecentsAPI",
value: function getRecentsAPI() {
this.destroy();
this.recentsAPI = new RecentsAPI(this.options);
return this.recentsAPI;
}
/**
* API for metadata
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {MetadataAPI} MetadataAPI instance
*/
}, {
key: "getMetadataAPI",
value: function getMetadataAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.metadataAPI = new MetadataAPI(this.options);
return this.metadataAPI;
}
/**
* API for versions
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {VersionsAPI} VersionsAPI instance
*/
}, {
key: "getVersionsAPI",
value: function getVersionsAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.versionsAPI = new VersionsAPI(this.options);
return this.versionsAPI;
}
/**
* API for comments
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {CommentsAPI} CommentsAPI instance
*/
}, {
key: "getCommentsAPI",
value: function getCommentsAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.commentsAPI = new CommentsAPI(this.options);
return this.commentsAPI;
}
/**
* API for tasks
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {TasksAPI} TasksAPI instance
*/
}, {
key: "getTasksAPI",
value: function getTasksAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.tasksAPI = new TasksAPI(this.options);
return this.tasksAPI;
}
/**
* API for tasks
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {TasksAPI} TaskAssignmentsAPI instance
*/
}, {
key: "getTaskAssignmentsAPI",
value: function getTaskAssignmentsAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.taskAssignmentsAPI = new TaskAssignmentsAPI(this.options);
return this.taskAssignmentsAPI;
}
/**
* API for tasks
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {TasksAPI} TaskAssignmentsAPI instance
*/
}, {
key: "getTasksNewAPI",
value: function getTasksNewAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.tasksNewAPI = new TasksNewAPI(this.options);
return this.tasksNewAPI;
}
/**
* API for taskCollaborators
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {TaskCollaboratorsAPI} TaskCollaboratorsAPI instance
*/
}, {
key: "getTaskCollaboratorsAPI",
value: function getTaskCollaboratorsAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.taskCollaboratorsAPI = new TaskCollaboratorsAPI(this.options);
return this.taskCollaboratorsAPI;
}
/**
* API for taskLinks
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {TasksAPI} TaskLinksAPI instance
*/
}, {
key: "getTaskLinksAPI",
value: function getTaskLinksAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.taskLinksAPI = new TaskLinksAPI(this.options);
return this.taskLinksAPI;
}
/**
* API for file access stats
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {FileAccessStatsAPI} FileAccessStatsAPI instance
*/
}, {
key: "getFileAccessStatsAPI",
value: function getFileAccessStatsAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.fileAccessStatsAPI = new FileAccessStatsAPI(this.options);
return this.fileAccessStatsAPI;
}
/**
* API for file collaborators
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {FileCollaboratorsAPI} FileCollaboratorsAPI instance
*/
}, {
key: "getFileCollaboratorsAPI",
value: function getFileCollaboratorsAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.fileCollaboratorsAPI = new FileCollaboratorsAPI(this.options);
return this.fileCollaboratorsAPI;
}
/**
* API for Users
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {UsersAPI} UsersAPI instance
*/
}, {
key: "getUsersAPI",
value: function getUsersAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.usersAPI = new UsersAPI(this.options);
return this.usersAPI;
}
/**
* API for Feed Items
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {FeedAPI} FeedAPI instance
*/
}, {
key: "getFeedAPI",
value: function getFeedAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.feedItemsAPI = new FeedAPI(this.options);
return this.feedItemsAPI;
}
/**
* API for Open With
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {OpenWithAPI} OpenWithAPI instance
*/
}, {
key: "getOpenWithAPI",
value: function getOpenWithAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.openWithAPI = new OpenWithAPI(this.options);
return this.openWithAPI;
}
/**
* API for the App Integrations endpoint
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {AppIntegrationsAPI} AppIntegrationsAPI instance
*/
}, {
key: "getAppIntegrationsAPI",
value: function getAppIntegrationsAPI(shouldDestroy) {
if (shouldDestroy) {
this.destroy();
}
this.appIntegrationsAPI = new AppIntegrationsAPI(this.options);
return this.appIntegrationsAPI;
}
/**
* API for Metadata Query
*
* @param {boolean} shouldDestroy - true if the factory should destroy before returning the call
* @return {MetadataQuery} MetadataQuery instance
*/
}, {
key: "getMetadataQueryAPI",
value: function getMetadataQueryAPI() {
var shouldDestroy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (shouldDestroy) {
this.destroy();
}
this.metadataQueryAPI = new MetadataQueryAPI(this.options);
return this.metadataQueryAPI;
}
/**
* API for Box Edit
*
* @return {BoxEditAPI} BoxEditAPI instance
*/
}, {
key: "getBoxEditAPI",
value: function getBoxEditAPI() {
this.boxEditAPI = new BoxEditAPI();
return this.boxEditAPI;
}
}]);
return APIFactory;
}();
export default APIFactory;