UNPKG

@putdotio/api-client

Version:

JavaScript SDK for interacting with the put.io API.

1,776 lines (1,492 loc) 45.1 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var axios = _interopDefault(require('axios')); var qs = _interopDefault(require('qs')); var EventEmitter = _interopDefault(require('event-emitter')); var jsBase64 = require('js-base64'); var URI = _interopDefault(require('urijs')); 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); } var mockRequestConfig = {}; var mockPutioAPIClientResponse = { config: mockRequestConfig, data: { foo: 'bar', status: 'OK' }, headers: { 'x-trace-id': 'MOCK_TRACE_ID' }, status: 200, statusText: 'ok' }; var mockAxiosError = { config: mockRequestConfig, isAxiosError: true, name: 'AXIOS_ERROR', message: 'AXIOS_ERROR_MESSAGE', toJSON: function toJSON() { return { name: this.name, message: this.message }; } }; var mockPutioAPIClientError = /*#__PURE__*/_extends({}, mockAxiosError, { data: { error_type: 'MOCK_ERROR', error_message: 'MOCK_MESSAGE', status_code: 0, extra: { foo: 'bar' } }, toJSON: function toJSON() { return this.data; } }); var createMockResponse = function createMockResponse(data, status) { if (status === void 0) { status = 200; } return { config: mockRequestConfig, data: _extends({}, data, { status: 'OK' }), status: status, headers: {}, statusText: 'ok' }; }; var createMockErrorResponse = function createMockErrorResponse(data) { return _extends({}, mockAxiosError, { data: data, toJSON: function toJSON() { return this.data; } }); }; function createMockXMLHttpRequest(readyState, status, responseText) { var xhr = new XMLHttpRequest(); return new Proxy(xhr, { get: function get(target, prop) { if (prop === 'readyState') return readyState; if (prop === 'status') return status; if (prop === 'responseText') return responseText; // @ts-ignore return target[prop]; } }); } var DEFAULT_CLIENT_OPTIONS = { baseURL: 'https://api.put.io/v2', clientID: 1, webAppURL: 'https://app.put.io' }; var ACCOUNT_CLEAR_OPTION_KEYS = ['files', 'finished_transfers', 'active_transfers', 'rss_feeds', 'rss_logs', 'history', 'trash', 'friends']; var FileSortOptions = { NAME_ASC: 'NAME_ASC', NAME_DESC: 'NAME_DESC', SIZE_ASC: 'SIZE_ASC', SIZE_DESC: 'SIZE_DESC', DATE_ASC: 'DATE_ASC', DATE_DESC: 'DATE_DESC', MODIFIED_ASC: 'MODIFIED_ASC', MODIFIED_DESC: 'MODIFIED_DESC' }; var identity = function identity(arg) { return arg; }; var isPutioAPIErrorResponse = function isPutioAPIErrorResponse(input) { return typeof input === 'object' && !!input && !!input.error_type; }; var isPutioAPIError = function isPutioAPIError(input) { return typeof input === 'object' && !!input && !!input.data && isPutioAPIErrorResponse(input.data); }; var createFormDataFromObject = function createFormDataFromObject(obj) { return Object.keys(obj).reduce(function (data, key) { data.append(key, obj[key]); return data; }, new FormData()); }; var EVENTS = { ERROR: 'ERROR', CLIENT_IP_CHANGED: 'CLIENT_IP_CHANGED' }; var eventEmitter = /*#__PURE__*/EventEmitter(); var IP_HEADER_KEY = 'putio-client-ip'; var createClientIPChangeEmitter = function createClientIPChangeEmitter() { var IP = ''; var checkIP = function checkIP(response) { var newIP = response.headers[IP_HEADER_KEY]; if (!IP) { IP = newIP; return; } if (newIP && IP !== newIP) { eventEmitter.emit(EVENTS.CLIENT_IP_CHANGED, { IP: IP, newIP: newIP }); IP = newIP; return; } }; return { onFulfilled: function onFulfilled(response) { checkIP(response); return response; }, onRejected: function onRejected(error) { if (error.response) { checkIP(error.response); } return Promise.reject(error); } }; }; var createErrorEmitter = function createErrorEmitter() { return { onFulfilled: identity, onRejected: function onRejected(error) { eventEmitter.emit(EVENTS.ERROR, error); return Promise.reject(error); } }; }; var createResponseFormatter = function createResponseFormatter() { return { onFulfilled: function onFulfilled(response) { return _extends({}, response, { body: response.data }); }, onRejected: function onRejected(error) { if (!axios.isAxiosError(error)) { return Promise.reject(error); } try { var _error$response; var errorData = { 'x-trace-id': (_error$response = error.response) == null ? void 0 : _error$response.headers['x-trace-id'], error_message: error.message, error_type: 'ERROR', status_code: 0, extra: {} }; // ECONNABORTED is the code for a request that timed out in axios. if (error.code === 'ECONNABORTED') { errorData = _extends({}, errorData, { status_code: 408, error_message: 'Request timed out' }); } if (error.response && error.response.data) { var _error$response2 = error.response, status = _error$response2.status, data = _error$response2.data; errorData = isPutioAPIErrorResponse(data) ? _extends({}, errorData, data, { status_code: status }) : _extends({}, errorData, { status_code: status }); } else if (error.request instanceof XMLHttpRequest && error.request.readyState === 4) { var _error$request = error.request, _status = _error$request.status, responseText = _error$request.responseText; var _data = JSON.parse(responseText); errorData = _extends({}, errorData, _data, { status_code: _status }); } var formattedError = _extends({}, error, { data: errorData, toJSON: function toJSON() { return errorData; } }); return Promise.reject(formattedError); } catch (e) { return Promise.reject(error); } } }; }; var Account = /*#__PURE__*/function () { function Account(client) { this.client = client; } var _proto = Account.prototype; _proto.Info = function Info(params) { if (params === void 0) { params = {}; } return this.client.get('/account/info', { params: params }); }; _proto.Settings = function Settings() { return this.client.get('/account/settings'); }; _proto.SaveSettings = function SaveSettings(payload) { return this.client.post('/account/settings', { data: payload }); }; _proto.Clear = function Clear(options) { return this.client.post('/account/clear', { data: options }); }; _proto.Destroy = function Destroy(currentPassword) { return this.client.post('/account/destroy', { data: { current_password: currentPassword } }); }; _proto.Confirmations = function Confirmations(type) { return this.client.get('/account/confirmation/list', { data: { type: type } }); }; return Account; }(); var TwoFactor = /*#__PURE__*/function () { function TwoFactor(client) { this.client = client; } var _proto = TwoFactor.prototype; _proto.GenerateTOTP = function GenerateTOTP() { return this.client.post('/two_factor/generate/totp'); }; _proto.VerifyTOTP = function VerifyTOTP(twoFactorScopedToken, code) { return this.client.post('/two_factor/verify/totp', { params: { oauth_token: twoFactorScopedToken }, data: { code: code } }); }; _proto.GetRecoveryCodes = function GetRecoveryCodes() { return this.client.get('/two_factor/recovery_codes'); }; _proto.RegenerateRecoveryCodes = function RegenerateRecoveryCodes() { return this.client.post('/two_factor/recovery_codes/refresh'); }; return TwoFactor; }(); var Auth = /*#__PURE__*/function () { function Auth(client) { this.client = client; this.TwoFactor = new TwoFactor(client); } var _proto2 = Auth.prototype; _proto2.GetLoginURL = function GetLoginURL(_ref) { var redirectURI = _ref.redirectURI, _ref$responseType = _ref.responseType, responseType = _ref$responseType === void 0 ? 'token' : _ref$responseType, state = _ref.state, clientID = _ref.clientID, clientName = _ref.clientName; var options = this.client.options; var url = new URI(options.webAppURL + "/authenticate").addQuery({ client_id: clientID || options.clientID, client_name: clientName, redirect_uri: redirectURI, response_type: responseType, isolated: 1, state: state }); return url.toString(); }; _proto2.Login = function Login(_ref2) { var username = _ref2.username, password = _ref2.password, app = _ref2.app; return this.client.put("/oauth2/authorizations/clients/" + app.client_id + "?client_secret=" + app.client_secret, { headers: { Authorization: "Basic " + jsBase64.Base64.encode(username + ":" + password) } }); }; _proto2.Logout = function Logout() { return this.client.post('/oauth/grants/logout'); }; _proto2.Register = function Register(data) { return this.client.post('/registration/register', { data: _extends({ client_id: this.client.options.clientID }, data) }); }; _proto2.Exists = function Exists(key, value) { return this.client.get("/registration/exists/" + key, { params: { value: value } }); }; _proto2.GetVoucher = function GetVoucher(code) { return this.client.get("/registration/voucher/" + code); }; _proto2.GetGiftCard = function GetGiftCard(code) { return this.client.get("/registration/gift_card/" + code); }; _proto2.GetFamilyInvite = function GetFamilyInvite(code) { return this.client.get("/registration/family/" + code); }; _proto2.ForgotPassword = function ForgotPassword(mail) { return this.client.post('/registration/password/forgot', { data: { mail: mail } }); }; _proto2.ResetPassword = function ResetPassword(key, newPassword) { return this.client.post('/registration/password/reset', { data: { key: key, password: newPassword } }); }; _proto2.GetCode = function GetCode(clientID, clientName) { return this.client.get('/oauth2/oob/code', { params: { app_id: clientID, client_name: clientName } }); }; _proto2.CheckCodeMatch = function CheckCodeMatch(code) { return this.client.get("/oauth2/oob/code/" + code); }; _proto2.LinkDevice = function LinkDevice(code) { return this.client.post('/oauth2/oob/code', { data: { code: code } }); }; _proto2.Grants = function Grants() { return this.client.get('/oauth/grants/'); }; _proto2.RevokeApp = function RevokeApp(id) { return this.client.post("/oauth/grants/" + id + "/delete"); }; _proto2.Clients = function Clients() { return this.client.get('/oauth/clients/'); }; _proto2.RevokeClient = function RevokeClient(id) { return this.client.post("/oauth/clients/" + id + "/delete"); }; _proto2.RevokeAllClients = function RevokeAllClients() { return this.client.post('/oauth/clients/delete-all'); }; _proto2.ValidateToken = function ValidateToken(token) { return this.client.get('/oauth2/validate', { params: { oauth_token: token } }); }; return Auth; }(); var OAuth = /*#__PURE__*/function () { function OAuth(client) { this.client = client; } var _proto = OAuth.prototype; _proto.GetAuthorizeURL = function GetAuthorizeURL(query) { if (query === void 0) { query = {}; } var _this$client = this.client, token = _this$client.token, baseURL = _this$client.options.baseURL; var uri = new URI(baseURL + "/oauth2/authorize").addQuery(_extends({}, query, { oauth_token: token })); return uri.toString(); }; _proto.Query = function Query() { return this.client.get('/oauth/apps'); }; _proto.Get = function Get(id) { return this.client.get("/oauth/apps/" + id); }; _proto.GetIconURL = function GetIconURL(id) { var _this$client2 = this.client, token = _this$client2.token, baseURL = _this$client2.options.baseURL; return baseURL + "/oauth/apps/" + id + "/icon?oauth_token=" + token; }; _proto.SetIcon = function SetIcon(id, data) { return this.client.post("/oauth/apps/" + id + "/icon", { data: data }); }; _proto.Create = function Create(app) { return this.client.post('/oauth/apps/register', { data: createFormDataFromObject(app) }); }; _proto.Update = function Update(app) { return this.client.post("/oauth/apps/" + app.id, { data: createFormDataFromObject(app) }); }; _proto.Delete = function Delete(id) { return this.client.post("/oauth/apps/" + id + "/delete"); }; _proto.RegenerateToken = function RegenerateToken(id) { return this.client.post("/oauth/apps/" + id + "/regenerate_token"); }; _proto.GetPopularApps = function GetPopularApps() { return this.client.get('/oauth/apps/popular'); }; return OAuth; }(); var DownloadLinks = /*#__PURE__*/function () { function DownloadLinks(client) { this.client = client; } var _proto = DownloadLinks.prototype; _proto.Create = function Create(_ref) { var _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, cursor = _ref.cursor, _ref$excludeIds = _ref.excludeIds, excludeIds = _ref$excludeIds === void 0 ? [] : _ref$excludeIds; return this.client.post('/download_links/create', { data: { file_ids: ids.join(','), exclude_ids: excludeIds.join(','), cursor: cursor } }); }; _proto.Get = function Get(downloadLinksId) { return this.client.get("/download_links/" + downloadLinksId); }; return DownloadLinks; }(); var Sharing = /*#__PURE__*/function () { function Sharing(client) { this.client = client; } var _proto = Sharing.prototype; _proto.Clone = function Clone(_ref) { var _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, cursor = _ref.cursor, _ref$excludeIds = _ref.excludeIds, excludeIds = _ref$excludeIds === void 0 ? [] : _ref$excludeIds, _ref$parentId = _ref.parentId, parentId = _ref$parentId === void 0 ? 0 : _ref$parentId; return this.client.post('/sharing/clone', { data: { file_ids: ids.join(','), exclude_ids: excludeIds.join(','), parent_id: parentId, cursor: cursor } }); }; _proto.CloneInfo = function CloneInfo(cloneInfoId) { return this.client.get("/sharing/clone/" + cloneInfoId); }; return Sharing; }(); var Config = /*#__PURE__*/function () { function Config(client) { this.client = client; } var _proto = Config.prototype; _proto.Read = function Read() { return this.client.get('/config'); }; _proto.Write = function Write(config) { return this.client.put('/config', { data: { config: config } }); }; _proto.GetKey = function GetKey(key) { return this.client.get("/config/" + key); }; _proto.SetKey = function SetKey(key, value) { return this.client.put("/config/" + key, { data: { value: value } }); }; _proto.DeleteKey = function DeleteKey(key) { return this.client["delete"]("/config/" + key); }; return Config; }(); var PutioEvents = /*#__PURE__*/function () { function PutioEvents(client) { this.client = client; } var _proto = PutioEvents.prototype; _proto.Query = function Query() { return this.client.get('/events/list'); }; _proto.Delete = function Delete(id) { return this.client.post("/events/delete/" + id); }; _proto.Clear = function Clear() { return this.client.post('/events/delete'); }; return PutioEvents; }(); var File = /*#__PURE__*/function () { function File(client) { this.client = client; } var _proto = File.prototype; _proto.Download = function Download(fileId) { return this.client.get("/files/" + fileId + "/download"); }; _proto.GetStorageURL = function GetStorageURL(fileId) { return this.client.get("/files/" + fileId + "/url"); }; _proto.GetContent = function GetContent(fileId) { return this.client.get("/files/" + fileId + "/stream"); }; _proto.Subtitles = function Subtitles(fileId, oauthToken, languages) { return this.client.get("/files/" + fileId + "/subtitles", { params: { languages: languages, oauth_token: oauthToken } }); }; _proto.GetHLSStreamURL = function GetHLSStreamURL(fileId, _temp) { var _ref = _temp === void 0 ? {} : _temp, _ref$token = _ref.token, token = _ref$token === void 0 ? '' : _ref$token, _ref$subtitleLanguage = _ref.subtitleLanguages, subtitleLanguages = _ref$subtitleLanguage === void 0 ? [] : _ref$subtitleLanguage, maxSubtitleCount = _ref.maxSubtitleCount, playOriginal = _ref.playOriginal; return new URI(this.client.options.baseURL + "/files/" + fileId + "/hls/media.m3u8").addQuery({ oauth_token: token || this.client.token, subtitle_languages: subtitleLanguages, max_subtitle_count: maxSubtitleCount, original: typeof playOriginal === 'boolean' ? playOriginal ? 1 : 0 : undefined }).toString(); }; _proto.ConvertToMp4 = function ConvertToMp4(fileId) { return this.client.post("/files/" + fileId + "/mp4"); }; _proto.ConvertStatus = function ConvertStatus(fileId) { return this.client.get("/files/" + fileId + "/mp4"); }; _proto.DeleteMp4 = function DeleteMp4(fileId) { return this.client["delete"]("/files/" + fileId + "/mp4"); }; _proto.SharedWith = function SharedWith(fileId) { return this.client.get("/files/" + fileId + "/shared-with"); }; _proto.Unshare = function Unshare(fileId, shareId) { var shares = shareId; if (shares) { shares = Array.isArray(shares) ? shares.map(function (i) { return i.toString(); }) : [shares.toString()]; shares = shares.join(','); } return this.client.post("/files/" + fileId + "/unshare", { data: { shares: shares || 'everyone' } }); }; _proto.SaveAsMp4 = function SaveAsMp4(fileId) { return this.client.get("/files/" + fileId + "/put-mp4-to-my-folders"); }; _proto.Rename = function Rename(fileId, name) { return this.client.post('/files/rename', { data: { file_id: fileId, name: name } }); }; _proto.GetStartFrom = function GetStartFrom(fileId) { return this.client.get("/files/" + fileId + "/start-from"); }; _proto.SetStartFrom = function SetStartFrom(fileId, time) { return this.client.post("/files/" + fileId + "/start-from/set", { data: { time: parseInt(time, 10) } }); }; _proto.ResetStartFrom = function ResetStartFrom(fileId) { return this.client.get("/files/" + fileId + "/start-from/delete"); }; _proto.Extract = function Extract(fileId, password) { return this.client.post('/files/extract', { data: { password: password, user_file_ids: [fileId.toString()] } }); }; _proto.FindNextFile = function FindNextFile(fileId, fileType) { return this.client.get("/files/" + fileId + "/next-file", { params: { file_type: fileType } }); }; _proto.FindNextVideo = function FindNextVideo(fileId) { return this.client.get("/files/" + fileId + "/next-video"); }; return File; }(); var Files = /*#__PURE__*/function () { function Files(client) { this.client = client; } var _proto = Files.prototype; _proto.Query = function Query(id, _temp) { var _ref = _temp === void 0 ? {} : _temp, perPage = _ref.perPage, sortBy = _ref.sortBy, contentType = _ref.contentType, fileType = _ref.fileType, streamUrl = _ref.streamUrl, streamUrlParent = _ref.streamUrlParent, mp4StreamUrl = _ref.mp4StreamUrl, mp4StreamUrlParent = _ref.mp4StreamUrlParent, hidden = _ref.hidden, mp4Status = _ref.mp4Status, mp4StatusParent = _ref.mp4StatusParent, videoMetadata = _ref.videoMetadata, videoMetadataParent = _ref.videoMetadataParent, codecsParent = _ref.codecsParent, mediaInfoParent = _ref.mediaInfoParent, breadcrumbs = _ref.breadcrumbs, total = _ref.total; return this.client.get("/files/" + (id === 'friends' ? 'items-shared-with-you' : 'list'), { params: { parent_id: id !== 'friends' ? id : null, per_page: perPage, sort_by: sortBy, content_type: contentType, file_type: fileType, stream_url: streamUrl, stream_url_parent: streamUrlParent, mp4_stream_url: mp4StreamUrl, mp4_stream_url_parent: mp4StreamUrlParent, hidden: hidden, mp4_status: mp4Status, mp4_status_parent: mp4StatusParent, video_metadata: videoMetadata, video_metadata_parent: videoMetadataParent, codecs_parent: codecsParent, media_info_parent: mediaInfoParent, breadcrumbs: breadcrumbs, total: total } }); }; _proto.Continue = function Continue(cursor, _temp2) { var _ref2 = _temp2 === void 0 ? {} : _temp2, perPage = _ref2.perPage; return this.client.post('/files/list/continue', { data: { cursor: cursor }, params: { per_page: perPage } }); }; _proto.Search = function Search(query, _temp3) { var _ref3 = _temp3 === void 0 ? { perPage: 50 } : _temp3, perPage = _ref3.perPage, fileType = _ref3.fileType; return this.client.get('/files/search', { params: { query: query, per_page: perPage, type: fileType } }); }; _proto.ContinueSearch = function ContinueSearch(cursor, _temp4) { var _ref4 = _temp4 === void 0 ? {} : _temp4, perPage = _ref4.perPage; return this.client.post('/files/search/continue', { data: { cursor: cursor }, params: { per_page: perPage } }); }; _proto.NewFolder = function NewFolder(name, parentId) { if (parentId === void 0) { parentId = 0; } return this.CreateFolder({ name: name, parentId: parentId }); }; _proto.CreateFolder = function CreateFolder(_ref5) { var name = _ref5.name, parentId = _ref5.parentId, path = _ref5.path; return this.client.post('/files/create-folder', { data: { name: name, parent_id: parentId, path: path } }); }; _proto.DeleteAll = function DeleteAll(cursor, excludeIds, _ref6) { if (excludeIds === void 0) { excludeIds = []; } var _ref6$partialDelete = _ref6.partialDelete, partialDelete = _ref6$partialDelete === void 0 ? false : _ref6$partialDelete, skipTrash = _ref6.skipTrash; return this.client.post('/files/delete', { data: { cursor: cursor, exclude_ids: excludeIds.join(',') }, params: { skip_nonexistents: true, partial_delete: partialDelete, skip_trash: skipTrash } }); }; _proto.Delete = function Delete(ids, _temp5) { if (ids === void 0) { ids = []; } var _ref7 = _temp5 === void 0 ? {} : _temp5, _ref7$ignoreFileOwner = _ref7.ignoreFileOwner, ignoreFileOwner = _ref7$ignoreFileOwner === void 0 ? false : _ref7$ignoreFileOwner, _ref7$partialDelete = _ref7.partialDelete, partialDelete = _ref7$partialDelete === void 0 ? false : _ref7$partialDelete, skipTrash = _ref7.skipTrash; return this.client.post('/files/delete', { data: { file_ids: ids.join(',') }, params: { skip_nonexistents: true, skip_owner_check: ignoreFileOwner, partial_delete: partialDelete, skip_trash: skipTrash } }); }; _proto.Extract = function Extract(_ref8) { var _ref8$ids = _ref8.ids, ids = _ref8$ids === void 0 ? [] : _ref8$ids, cursor = _ref8.cursor, _ref8$excludeIds = _ref8.excludeIds, excludeIds = _ref8$excludeIds === void 0 ? [] : _ref8$excludeIds; return this.client.post('/files/extract', { data: { user_file_ids: ids.join(','), exclude_ids: excludeIds.join(','), cursor: cursor } }); }; _proto.ExtractStatus = function ExtractStatus() { return this.client.get('/files/extract'); }; _proto.Share = function Share(_ref9) { var _ref9$ids = _ref9.ids, ids = _ref9$ids === void 0 ? [] : _ref9$ids, cursor = _ref9.cursor, _ref9$excludeIds = _ref9.excludeIds, excludeIds = _ref9$excludeIds === void 0 ? [] : _ref9$excludeIds, friends = _ref9.friends; return this.client.post('/files/share', { data: { cursor: cursor, friends: friends, file_ids: ids.join(','), exclude_ids: excludeIds.join(',') } }); }; _proto.Move = function Move(ids, to) { return this.client.post('/files/move', { data: { file_ids: ids.join(','), parent_id: to } }); }; _proto.MoveAll = function MoveAll(_ref10) { var cursor = _ref10.cursor, _ref10$excludeIds = _ref10.excludeIds, excludeIds = _ref10$excludeIds === void 0 ? [] : _ref10$excludeIds, to = _ref10.to; return this.client.post('/files/move', { data: { cursor: cursor, parent_id: to, exclude_ids: excludeIds.join(',') } }); }; _proto.ConvertToMp4 = function ConvertToMp4(_ref11) { var _ref11$ids = _ref11.ids, ids = _ref11$ids === void 0 ? [] : _ref11$ids, cursor = _ref11.cursor, _ref11$excludeIds = _ref11.excludeIds, excludeIds = _ref11$excludeIds === void 0 ? [] : _ref11$excludeIds; return this.client.post('/files/convert_mp4', { data: { file_ids: ids.join(','), exclude_ids: excludeIds.join(','), cursor: cursor } }); }; _proto.SharedOnes = function SharedOnes() { return this.client.get('/files/shared'); }; _proto.PublicShares = function PublicShares() { return this.client.get('/files/public/list'); }; _proto.SetWatchStatus = function SetWatchStatus(_ref12) { var _ref12$ids = _ref12.ids, ids = _ref12$ids === void 0 ? [] : _ref12$ids, cursor = _ref12.cursor, _ref12$excludeIds = _ref12.excludeIds, excludeIds = _ref12$excludeIds === void 0 ? [] : _ref12$excludeIds, watched = _ref12.watched; return this.client.post('/files/watch-status', { data: { file_ids: ids.join(','), exclude_ids: excludeIds.join(','), cursor: cursor, watched: watched } }); }; _proto.Upload = function Upload(_ref13) { var file = _ref13.file, fileName = _ref13.fileName, _ref13$parentId = _ref13.parentId, parentId = _ref13$parentId === void 0 ? 0 : _ref13$parentId; var form = new FormData(); form.append('file', file); if (fileName) { form.append('filename', fileName); } if (parentId) { form.append('parent_id', parentId.toString()); } return this.client.post('/files/upload', { data: form, headers: { 'Content-Type': 'multipart/form-data' } }); }; return Files; }(); var FriendInvites = /*#__PURE__*/function () { function FriendInvites(client) { this.client = client; } var _proto = FriendInvites.prototype; _proto.GetAll = function GetAll() { return this.client.get('/account/friend_invites'); }; _proto.Create = function Create() { return this.client.post('/account/create_friend_invitation'); }; return FriendInvites; }(); var Friends = /*#__PURE__*/function () { function Friends(client) { this.client = client; } var _proto = Friends.prototype; _proto.Query = function Query() { return this.client.get('/friends/list'); }; _proto.Search = function Search(username) { return this.client.get("/friends/user-search/" + username); }; _proto.WaitingRequests = function WaitingRequests() { return this.client.get('/friends/waiting-requests'); }; _proto.WaitingRequestsCount = function WaitingRequestsCount() { return this.client.get('/friends/waiting-requests-count'); }; _proto.SendFrienshipRequest = function SendFrienshipRequest(username) { return this.client.post("/friends/" + username + "/request"); }; _proto.Remove = function Remove(username) { return this.client.post("/friends/" + username + "/unfriend"); }; _proto.Approve = function Approve(username) { return this.client.post("/friends/" + username + "/approve"); }; _proto.Deny = function Deny(username) { return this.client.post("/friends/" + username + "/deny"); }; _proto.SharedFolder = function SharedFolder(username) { return this.client.get("/friends/" + username + "/files"); }; return Friends; }(); var IFTTT = /*#__PURE__*/function () { function IFTTT(client) { this.client = client; } var _proto = IFTTT.prototype; _proto.SendEvent = function SendEvent(_ref) { var clientName = _ref.clientName, eventType = _ref.eventType, _ref$ingredients = _ref.ingredients, ingredients = _ref$ingredients === void 0 ? {} : _ref$ingredients; return this.client.post('/ifttt-client/event', { data: { client_name: clientName, event_type: eventType, ingredients: ingredients } }); }; return IFTTT; }(); var Payment = /*#__PURE__*/function () { function Payment(client) { var _this = this; this.ChangePlan = { GET: function GET(params) { return _this.client.get("/payment/change_plan/" + params.plan_path, { params: { payment_type: params.payment_type, coupon_code: params.coupon_code } }); }, POST: function POST(params) { return _this.client.post("/payment/change_plan/" + params.plan_path, { data: { payment_type: params.payment_type, confirmation_code: params.confirmation_code }, params: { coupon_code: params.coupon_code } }); } }; this.client = client; } var _proto = Payment.prototype; _proto.Info = function Info() { return this.client.get('/payment/info'); }; _proto.Plans = function Plans() { return this.client.get('/payment/plans'); }; _proto.Options = function Options() { return this.client.get('/payment/options'); }; _proto.History = function History(_temp) { var _ref = _temp === void 0 ? {} : _temp, _ref$unReportedOnly = _ref.unReportedOnly, unReportedOnly = _ref$unReportedOnly === void 0 ? false : _ref$unReportedOnly; return this.client.get('/payment/history', { params: { unreported_only: unReportedOnly } }); }; _proto.Invites = function Invites() { return this.client.get('/payment/invites'); }; _proto.CreateNanoPaymentRequest = function CreateNanoPaymentRequest(_ref2) { var planCode = _ref2.planCode; return this.client.post('/payment/methods/nano/request', { data: { plan_code: planCode } }); }; _proto.CreateOpenNodeCharge = function CreateOpenNodeCharge(_ref3) { var planPath = _ref3.planPath; return this.client.post('/payment/methods/opennode/charge', { data: { plan_fs_path: planPath } }); }; _proto.CancelSubscription = function CancelSubscription() { return this.client.post('/payment/stop_subscription'); }; _proto.GetVoucherInfo = function GetVoucherInfo(code) { return this.client.get("/payment/redeem_voucher/" + code); }; _proto.RedeemVoucher = function RedeemVoucher(code) { return this.client.post("/payment/redeem_voucher/" + code); }; _proto.Report = function Report(paymentIds) { if (paymentIds === void 0) { paymentIds = []; } return this.client.post('/payment/report', { data: { payment_ids: paymentIds.join(',') } }); }; _proto.AddWaitingPayment = function AddWaitingPayment(data) { return this.client.post('/payment/paddle_waiting_payment', { data: data }); }; return Payment; }(); var RSS = /*#__PURE__*/function () { function RSS(client) { this.client = client; } var _proto = RSS.prototype; _proto.Query = function Query() { return this.client.get('/rss/list'); }; _proto.Get = function Get(id) { return this.client.get("/rss/" + id); }; _proto.Create = function Create(rss) { return this.client.post('/rss/create', { data: rss }); }; _proto.Update = function Update(id, rss) { return this.client.post("/rss/" + id, { data: rss }); }; _proto.Pause = function Pause(id) { return this.client.post("/rss/" + id + "/pause"); }; _proto.Resume = function Resume(id) { return this.client.post("/rss/" + id + "/resume"); }; _proto.Delete = function Delete(id) { return this.client.post("/rss/" + id + "/delete"); }; _proto.Logs = function Logs(id) { return this.client.get("/rss/" + id + "/items"); }; _proto.ClearLogs = function ClearLogs(id) { return this.client.post("/rss/" + id + "/clear-log"); }; _proto.RetryItem = function RetryItem(id, itemId) { return this.client.post("/rss/" + id + "/items/" + itemId + "/retry"); }; return RSS; }(); var Tranfers = /*#__PURE__*/function () { function Tranfers(client) { this.client = client; } var _proto = Tranfers.prototype; _proto.Add = function Add(params) { return this.client.post('/transfers/add', { data: params }); }; _proto.AddMulti = function AddMulti(params) { return this.client.post('/transfers/add-multi', { data: { urls: JSON.stringify(params) } }); }; _proto.Get = function Get(id) { return this.client.get("/transfers/" + id); }; _proto.Query = function Query(_temp) { var _ref = _temp === void 0 ? {} : _temp, perPage = _ref.perPage, total = _ref.total; return this.client.get('/transfers/list', { params: { per_page: perPage, total: total } }); }; _proto.Continue = function Continue(cursor, _temp2) { var _ref2 = _temp2 === void 0 ? {} : _temp2, perPage = _ref2.perPage; return this.client.post('/transfers/list/continue', { data: { cursor: cursor, per_page: perPage } }); }; _proto.ClearAll = function ClearAll() { return this.client.post('/transfers/clean'); }; _proto.Cancel = function Cancel(ids) { if (ids === void 0) { ids = []; } return this.client.post('/transfers/cancel', { data: { transfer_ids: ids.join(',') } }); }; _proto.Retry = function Retry(id) { return this.client.post('/transfers/retry', { data: { id: id } }); }; _proto.Reannounce = function Reannounce(id) { return this.client.post('/transfers/reannounce', { data: { id: id } }); }; _proto.Count = function Count() { return this.client.get('/transfers/count'); }; return Tranfers; }(); var Trash = /*#__PURE__*/function () { function Trash(client) { this.client = client; } var _proto = Trash.prototype; _proto.List = function List(_temp) { var _ref = _temp === void 0 ? {} : _temp, _ref$limit = _ref.limit, limit = _ref$limit === void 0 ? 50 : _ref$limit; return this.client.get('/trash/list', { params: { per_page: limit } }); }; _proto.Continue = function Continue(cursor, _temp2) { var _ref2 = _temp2 === void 0 ? {} : _temp2, _ref2$limit = _ref2.limit, limit = _ref2$limit === void 0 ? 50 : _ref2$limit; return this.client.post('/trash/list/continue', { data: { cursor: cursor, per_page: limit } }); }; _proto.Restore = function Restore(_ref3) { var _ref3$useCursor = _ref3.useCursor, useCursor = _ref3$useCursor === void 0 ? false : _ref3$useCursor, _ref3$ids = _ref3.ids, ids = _ref3$ids === void 0 ? [] : _ref3$ids, cursor = _ref3.cursor; return this.client.post('/trash/restore', { data: { cursor: useCursor ? cursor : undefined, file_ids: !useCursor ? ids.join(',') : undefined } }); }; _proto.Delete = function Delete(_ref4) { var _ref4$useCursor = _ref4.useCursor, useCursor = _ref4$useCursor === void 0 ? false : _ref4$useCursor, _ref4$ids = _ref4.ids, ids = _ref4$ids === void 0 ? [] : _ref4$ids, cursor = _ref4.cursor; return this.client.post('/trash/delete', { data: { cursor: useCursor ? cursor : undefined, file_ids: !useCursor ? ids.join(',') : undefined } }); }; _proto.Empty = function Empty() { return this.client.post('/trash/empty'); }; return Trash; }(); var Tunnel = /*#__PURE__*/function () { function Tunnel(client) { this.client = client; } var _proto = Tunnel.prototype; _proto.Routes = function Routes() { return this.client.get('/tunnel/routes'); }; return Tunnel; }(); var User = /*#__PURE__*/function () { function User(client) { this.client = client; } /** * @deprecated Use `Account.Info` method instead. */ var _proto = User.prototype; _proto.Info = function Info(params) { return this.client.get('/account/info', { params: params }); } /** * @deprecated Use `Account.Settings` method instead. */ ; _proto.Settings = function Settings() { return this.client.get('/account/settings'); } /** * @deprecated Use `Account.SaveSettings` method instead. */ ; _proto.SaveSettings = function SaveSettings(settings) { return this.client.post('/account/settings', { data: settings }); } /** * @deprecated Use `Config.Read` method instead. */ ; _proto.Config = function Config() { return this.client.get('/config'); } /** * @deprecated Use `Config.Write` method instead. */ ; _proto.SaveConfig = function SaveConfig(config) { return this.client.put('/config', { data: { config: config } }); } /** * @deprecated Use `Account.Clear` method instead. */ ; _proto.ClearData = function ClearData(options) { return this.client.post('/account/clear', { data: options }); } /** * @deprecated Use `Account.Destroy` method instead. */ ; _proto.Destroy = function Destroy(currentPassword) { return this.client.post('/account/destroy', { data: { current_password: currentPassword } }); } /** * @deprecated Use `Account.Confirmations` method instead. */ ; _proto.Confirmations = function Confirmations(type) { return this.client.get('/account/confirmation/list', { data: { type: type } }); }; return User; }(); var Zips = /*#__PURE__*/function () { function Zips(client) { this.client = client; } var _proto = Zips.prototype; _proto.Query = function Query() { return this.client.get('/zips/list'); }; _proto.Create = function Create(_ref) { var cursor = _ref.cursor, _ref$excludeIds = _ref.excludeIds, excludeIds = _ref$excludeIds === void 0 ? [] : _ref$excludeIds, _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids; return this.client.post('/zips/create', { data: { cursor: cursor, exclude_ids: excludeIds.join(','), file_ids: ids.join(',') } }); }; _proto.Get = function Get(id) { return this.client.get("/zips/" + id); }; _proto.Retry = function Retry(id) { return this.client.get("/zips/" + id + "/retry"); }; _proto.Cancel = function Cancel(id) { return this.client.get("/zips/" + id + "/cancel"); }; return Zips; }(); var PutioAPIClient = /*#__PURE__*/function () { function PutioAPIClient(options) { this.options = _extends({}, PutioAPIClient.DEFAULT_OPTIONS, options); this.http = this.createHTTPClient(); this.Account = new Account(this); this.Auth = new Auth(this); this.DownloadLinks = new DownloadLinks(this); this.Sharing = new Sharing(this); this.Config = new Config(this); this.Events = new PutioEvents(this); this.Files = new Files(this); this.File = new File(this); this.Friends = new Friends(this); this.FriendInvites = new FriendInvites(this); this.OAuth = new OAuth(this); this.Payment = new Payment(this); this.RSS = new RSS(this); this.Transfers = new Tranfers(this); this.Trash = new Trash(this); this.Tunnel = new Tunnel(this); this.User = new User(this); this.Zips = new Zips(this); this.IFTTT = new IFTTT(this); } var _proto = PutioAPIClient.prototype; _proto.once = function once(event, listener) { eventEmitter.once(event, listener); }; _proto.on = function on(event, listener) { eventEmitter.on(event, listener); }; _proto.off = function off(event, listener) { eventEmitter.off(event, listener); }; _proto.configure = function configure(options) { this.options = _extends({}, this.options, options); return this; }; _proto.setToken = function setToken(token) { this.token = token; this.http.defaults.headers.common.Authorization = "token " + token; return this; }; _proto.clearToken = function clearToken() { this.token = undefined; this.http.defaults.headers.common.Authorization = ""; return this; }; _proto.get = function get(url, config) { return this.http(_extends({ method: 'GET', url: url }, config)); }; _proto.post = function post(url, config) { return this.http(_extends({ method: 'POST', url: url }, config)); }; _proto.put = function put(url, config) { return this.http(_extends({ method: 'PUT', url: url }, config)); }; _proto["delete"] = function _delete(url, config) { return this.http(_extends({ method: 'DELETE', url: url }, config)); }; _proto.createHTTPClient = function createHTTPClient() { var _this = this; var axiosInstance = axios.create({ baseURL: this.options.baseURL, withCredentials: true, timeout: 30000, paramsSerializer: function paramsSerializer(params) { return qs.stringify(params, { arrayFormat: 'comma' }); } }); // apply response interceptors var responseInterceptorFactories = [createResponseFormatter, createClientIPChangeEmitter, createErrorEmitter]; responseInterceptorFactories.map(function (createResponseInterceptor) { return createResponseInterceptor(_this.options); }).forEach(function (_ref) { var onFulfilled = _ref.onFulfilled, onRejected = _ref.onRejected; axiosInstance.interceptors.response.use(onFulfilled, onRejected); }); return axiosInstance; }; return PutioAPIClient; }(); PutioAPIClient.EVENTS = EVENTS; PutioAPIClient.DEFAULT_OPTIONS = DEFAULT_CLIENT_OPTIONS; exports.ACCOUNT_CLEAR_OPTION_KEYS = ACCOUNT_CLEAR_OPTION_KEYS; exports.DEFAULT_CLIENT_OPTIONS = DEFAULT_CLIENT_OPTIONS; exports.FileSortOptions = FileSortOptions; exports.createMockErrorResponse = createMockErrorResponse; exports.createMockResponse = createMockResponse; exports.createMockXMLHttpRequest = createMockXMLHttpRequest; exports.default = PutioAPIClient; exports.isPutioAPIError = isPutioAPIError; exports.isPutioAPIErrorResponse = isPutioAPIErrorResponse; exports.mockAxiosError = mockAxiosError; exports.mockPutioAPIClientError = mockPutioAPIClientError; exports.mockPutioAPIClientResponse = mockPutioAPIClientResponse; //# sourceMappingURL=api-client.cjs.development.js.map