Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions dist/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48109,6 +48109,14 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ });
/* harmony import */ var _baseApi__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../baseApi */ "./src/api/baseApi.ts");
/* harmony import */ var _functions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../functions */ "./src/functions/index.ts");
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _assert_this_initialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
Expand Down Expand Up @@ -48195,6 +48203,33 @@ function _inherits(subClass, superClass) {
});
if (superClass) _set_prototype_of(subClass, superClass);
}
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
Expand Down Expand Up @@ -48223,10 +48258,21 @@ function _set_prototype_of(o, p) {
};
return _set_prototype_of(o, p);
}
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _is_native_reflect_construct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
Expand Down Expand Up @@ -48527,6 +48573,66 @@ function _ts_generator(thisArg, body) {
});
})();
}
},
{
key: "stats",
value: /** get the stats of a user with a given range of dates
*
* @param range {DateRange}
* @returns {UserStats}
*/ function stats(range) {
var _this = this;
return _async_to_generator(function() {
var url, rangeParams, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value, response, json;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
url = _this._path + "/stats";
rangeParams = new URLSearchParams();
if (range) {
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(_iterator = Object.entries(range)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
_step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
rangeParams.append(key, value);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
url = url + "?" + rangeParams.toString();
}
return [
4,
_this.createHttpRequest.makeRequestwithDefault(url, "GET")
];
case 1:
response = _state.sent();
return [
4,
response.toJSON()
];
case 2:
json = _state.sent();
(0,_functions__WEBPACK_IMPORTED_MODULE_1__.propagateErrors)(json);
return [
2,
json
];
}
});
})();
}
}
]);
return UsersApi;
Expand Down
2 changes: 1 addition & 1 deletion dist/browser/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/index.min.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions dist/esm/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/esm/index.js.map

Large diffs are not rendered by default.

53 changes: 38 additions & 15 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,47 @@ type SocketData = {
totalJobs?: number;
};

type Long = {
low: number;
high: number;
unsigned: boolean;
};
type UserDoc = {
_id: string;
userId: string;
accountType: AccountType;
bandwidthUsage: Long;
totalStorageUsage: Long;
uploadLimit: Long;
storageLimit: Long;
Filesuploaded: Number;
FilesRecentStored: Number;
bandwidthUsage: number;
totalStorageUsage: number;
uploadLimit: number;
storageLimit: number;
Filesuploaded: number;
FilesRecentStored: number;
apiToken: Array<{
name: string;
key: string;
}>;
restrictIPs: Boolean;
restrictDomains: Boolean;
restrictIPs: boolean;
restrictDomains: boolean;
ipWhitelist: Array<String>;
domainWhitelist: Array<String>;
showAll: Boolean;
showAll: boolean;
};
type UserStats = {
data: {
storageUsage: number;
filesUploaded: number;
uploadLimit: number;
storageLimit: number;
filesRecentlyStored: number;
monthlyStats: Array<MonthlyStats>;
};
};
type MonthlyStats = {
month: string;
year: number;
bandwidthUsage: number;
filesUploaded: number;
requests: number;
};
/** user stats option */
type DateRange = {
from?: string;
to?: string;
};

type RequestData = Record<string, any>;
Expand Down Expand Up @@ -473,6 +490,12 @@ declare class UsersApi extends BaseApi {
* @returns loginResponse - {data:string} - the accessToken
*/
login(data: loginOptions): Promise<loginResponse>;
/** get the stats of a user with a given range of dates
*
* @param range {DateRange}
* @returns {UserStats}
*/
stats(range?: DateRange): Promise<UserStats>;
}

/**
Expand Down Expand Up @@ -671,4 +694,4 @@ declare class Client {
protected checkAuth(): Promise<validatedTokenResponse | undefined>;
}

export { Client, Color, ConfigOptions, EventName, EventProgress, FetchHttpClient, FetchHttpClientResponse, FileDoc, FileroomError, GlobalProgress, HttpClientInterface, HttpClientResponseInterface, LegacybrowserRawResponse, ProgressEvent, ProgressMap, RGBA, RequestData, RequestHeaders, RequestOptions, ResponseHeaderValue, ResponseHeaders, SocketData, StreamResponse, TimeoutError, UploadApi, UploadDeleteResponse, UploadEvents, UploadFile, UploadListners, UploadResult, UserDoc, awaitUploadResponse, createUserOptions, createUserResponse, deleteOneOptions, deleteResponse, existsResponse, getOptions, listOptions, listResponse, loginOptions, loginResponse, pinOptions, pinResponse, socketEvent, statusResponse, updateUserOptions, updateUserResponse, uploadOptions, validatedTokenResponse };
export { Client, Color, ConfigOptions, DateRange, EventName, EventProgress, FetchHttpClient, FetchHttpClientResponse, FileDoc, FileroomError, GlobalProgress, HttpClientInterface, HttpClientResponseInterface, LegacybrowserRawResponse, ProgressEvent, ProgressMap, RGBA, RequestData, RequestHeaders, RequestOptions, ResponseHeaderValue, ResponseHeaders, SocketData, StreamResponse, TimeoutError, UploadApi, UploadDeleteResponse, UploadEvents, UploadFile, UploadListners, UploadResult, UserDoc, UserStats, awaitUploadResponse, createUserOptions, createUserResponse, deleteOneOptions, deleteResponse, existsResponse, getOptions, listOptions, listResponse, loginOptions, loginResponse, pinOptions, pinResponse, socketEvent, statusResponse, updateUserOptions, updateUserResponse, uploadOptions, validatedTokenResponse };
22 changes: 22 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/api/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
validatedTokenResponse,
} from '../../interfaces';
import { propagateErrors, generateApiKey } from '../../functions';
import { UserStats, DateRange } from '../../types';

/**
*
Expand Down Expand Up @@ -129,4 +130,29 @@ export class UsersApi extends BaseApi {
}
return json as loginResponse;
}
/** get the stats of a user with a given range of dates
*
* @param range {DateRange}
* @returns {UserStats}
*/

async stats(range?: DateRange): Promise<UserStats> {
let url = this._path + '/stats';
let rangeParams = new URLSearchParams();
if (range) {
for (let [key, value] of Object.entries(range) as any) {
rangeParams.append(key, value);
}
url = url + '?' + rangeParams.toString();
}

const response = await this.createHttpRequest.makeRequestwithDefault(
url,
'GET',
);
let json = await response.toJSON();

propagateErrors(json);
return json as UserStats;
}
}
3 changes: 1 addition & 2 deletions src/interfaces/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FileDoc,UserDoc} from '../types';

import { FileDoc, UserDoc } from '../types';

/**Input Options for client.user.create
* @param userId - the userId can be provided without other fields to create a fileroom Account only for dartroomUsers.
Expand Down
49 changes: 34 additions & 15 deletions src/types/user.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import { AccountType } from '../enums';

type Long = {
low: number;
high: number;
unsigned: boolean;
}

export type UserDoc = {
_id: string;
userId: string;
accountType: AccountType;
bandwidthUsage: Long;
totalStorageUsage: Long;
uploadLimit: Long;
storageLimit: Long;
Filesuploaded: Number;
FilesRecentStored: Number;
bandwidthUsage: number;
totalStorageUsage: number;
uploadLimit: number;
storageLimit: number;
Filesuploaded: number;
FilesRecentStored: number;
apiToken: Array<{ name: string; key: string }>;
restrictIPs: Boolean;
restrictDomains: Boolean;
restrictIPs: boolean;
restrictDomains: boolean;
ipWhitelist: Array<String>;
domainWhitelist: Array<String>;
showAll: Boolean;
showAll: boolean;
};

export type UserStats = {
data: {
storageUsage: number;
filesUploaded: number;
uploadLimit: number;
storageLimit: number;
filesRecentlyStored: number;
monthlyStats: Array<MonthlyStats>;
};
};
type MonthlyStats = {
month: string;
year: number;
bandwidthUsage: number;
filesUploaded: number;
requests: number;
};

/** user stats option */

export type DateRange = {
from?: string;
to?: string;
};
Loading