@internxt/sdk 1.4.77 → 1.5.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/auth/index.d.ts +122 -122
  2. package/dist/auth/index.js +310 -310
  3. package/dist/auth/types.d.ts +54 -54
  4. package/dist/auth/types.js +26 -26
  5. package/dist/drive/backups/index.d.ts +18 -18
  6. package/dist/drive/backups/index.js +40 -40
  7. package/dist/drive/backups/types.d.ts +27 -27
  8. package/dist/drive/backups/types.js +2 -2
  9. package/dist/drive/index.d.ts +7 -7
  10. package/dist/drive/index.js +19 -19
  11. package/dist/drive/payments/index.d.ts +71 -53
  12. package/dist/drive/payments/index.js +208 -153
  13. package/dist/drive/payments/types.d.ts +176 -114
  14. package/dist/drive/payments/types.js +37 -32
  15. package/dist/drive/referrals/index.d.ts +19 -19
  16. package/dist/drive/referrals/index.js +50 -50
  17. package/dist/drive/referrals/types.d.ts +21 -21
  18. package/dist/drive/referrals/types.js +18 -18
  19. package/dist/drive/share/index.d.ts +319 -319
  20. package/dist/drive/share/index.js +540 -539
  21. package/dist/drive/share/types.d.ts +360 -358
  22. package/dist/drive/share/types.js +2 -2
  23. package/dist/drive/storage/index.d.ts +315 -195
  24. package/dist/drive/storage/index.js +630 -434
  25. package/dist/drive/storage/types.d.ts +473 -394
  26. package/dist/drive/storage/types.js +13 -13
  27. package/dist/drive/trash/index.d.ts +75 -55
  28. package/dist/drive/trash/index.js +180 -149
  29. package/dist/drive/trash/types.d.ts +29 -20
  30. package/dist/drive/trash/types.js +2 -2
  31. package/dist/drive/users/index.d.ts +135 -108
  32. package/dist/drive/users/index.js +204 -174
  33. package/dist/drive/users/types.d.ts +51 -43
  34. package/dist/drive/users/types.js +2 -2
  35. package/dist/index.d.ts +6 -5
  36. package/dist/index.js +31 -30
  37. package/dist/network/download.d.ts +8 -8
  38. package/dist/network/download.js +123 -123
  39. package/dist/network/errors/codes.d.ts +24 -24
  40. package/dist/network/errors/codes.js +48 -48
  41. package/dist/network/errors/context.d.ts +35 -35
  42. package/dist/network/errors/context.js +39 -39
  43. package/dist/network/errors/download.d.ts +4 -4
  44. package/dist/network/errors/download.js +48 -48
  45. package/dist/network/errors/index.d.ts +3 -3
  46. package/dist/network/errors/index.js +15 -15
  47. package/dist/network/errors/upload.d.ts +13 -13
  48. package/dist/network/errors/upload.js +78 -78
  49. package/dist/network/index.d.ts +70 -71
  50. package/dist/network/index.js +311 -310
  51. package/dist/network/types.d.ts +102 -102
  52. package/dist/network/types.js +18 -18
  53. package/dist/network/upload.d.ts +4 -4
  54. package/dist/network/upload.js +159 -159
  55. package/dist/photos/devices/index.d.ts +10 -10
  56. package/dist/photos/devices/index.js +79 -79
  57. package/dist/photos/index.d.ts +17 -17
  58. package/dist/photos/index.js +52 -52
  59. package/dist/photos/photos/index.d.ts +60 -60
  60. package/dist/photos/photos/index.js +225 -225
  61. package/dist/photos/shares/index.d.ts +8 -8
  62. package/dist/photos/shares/index.js +34 -34
  63. package/dist/photos/types.d.ts +154 -154
  64. package/dist/photos/types.js +19 -19
  65. package/dist/photos/users/index.d.ts +7 -7
  66. package/dist/photos/users/index.js +46 -46
  67. package/dist/shared/headers/index.d.ts +21 -18
  68. package/dist/shared/headers/index.js +79 -69
  69. package/dist/shared/http/client.d.ts +85 -85
  70. package/dist/shared/http/client.js +172 -181
  71. package/dist/shared/http/types.d.ts +7 -7
  72. package/dist/shared/http/types.js +2 -2
  73. package/dist/shared/index.d.ts +1 -1
  74. package/dist/shared/index.js +13 -13
  75. package/dist/shared/types/apiConnection.d.ts +12 -11
  76. package/dist/shared/types/apiConnection.js +2 -2
  77. package/dist/shared/types/appsumo.d.ts +16 -16
  78. package/dist/shared/types/appsumo.js +12 -12
  79. package/dist/shared/types/errors.d.ts +5 -4
  80. package/dist/shared/types/errors.js +28 -27
  81. package/dist/shared/types/teams.d.ts +9 -9
  82. package/dist/shared/types/teams.js +2 -2
  83. package/dist/shared/types/userSettings.d.ts +29 -27
  84. package/dist/shared/types/userSettings.js +2 -2
  85. package/dist/utils.d.ts +3 -3
  86. package/dist/utils.js +25 -25
  87. package/dist/workspaces/index.d.ts +176 -0
  88. package/dist/workspaces/index.js +415 -0
  89. package/dist/workspaces/index.test.d.ts +1 -0
  90. package/dist/workspaces/index.test.js +903 -0
  91. package/dist/workspaces/types.d.ts +291 -0
  92. package/dist/workspaces/types.js +2 -0
  93. package/package.json +1 -1
@@ -1,434 +1,630 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || function (mod) {
26
- if (mod && mod.__esModule) return mod;
27
- var result = {};
28
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
- __setModuleDefault(result, mod);
30
- return result;
31
- };
32
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
- return new (P || (P = Promise))(function (resolve, reject) {
35
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
- step((generator = generator.apply(thisArg, _arguments || [])).next());
39
- });
40
- };
41
- var __generator = (this && this.__generator) || function (thisArg, body) {
42
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
- function verb(n) { return function (v) { return step([n, v]); }; }
45
- function step(op) {
46
- if (f) throw new TypeError("Generator is already executing.");
47
- while (_) try {
48
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
49
- if (y = 0, t) op = [op[0] & 2, t.value];
50
- switch (op[0]) {
51
- case 0: case 1: t = op; break;
52
- case 4: _.label++; return { value: op[1], done: false };
53
- case 5: _.label++; y = op[1]; op = [0]; continue;
54
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
- default:
56
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
- if (t[2]) _.ops.pop();
61
- _.trys.pop(); continue;
62
- }
63
- op = body.call(thisArg, _);
64
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
- }
67
- };
68
- Object.defineProperty(exports, "__esModule", { value: true });
69
- exports.Storage = exports.StorageTypes = void 0;
70
- var headers_1 = require("../../shared/headers");
71
- var client_1 = require("../../shared/http/client");
72
- exports.StorageTypes = __importStar(require("./types"));
73
- var Storage = /** @class */ (function () {
74
- function Storage(apiUrl, appDetails, apiSecurity) {
75
- this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
76
- this.appDetails = appDetails;
77
- this.apiSecurity = apiSecurity;
78
- }
79
- Storage.client = function (apiUrl, appDetails, apiSecurity) {
80
- return new Storage(apiUrl, appDetails, apiSecurity);
81
- };
82
- /**
83
- * Creates a new folder
84
- * @param payload
85
- */
86
- Storage.prototype.createFolder = function (payload) {
87
- var _a = this.client.postCancellable('/storage/folder', {
88
- parentFolderId: payload.parentFolderId,
89
- folderName: payload.folderName,
90
- }, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
91
- return [promise, requestCanceler];
92
- };
93
- /**
94
- * Moves a specific folder to a new location
95
- * @param payload
96
- */
97
- Storage.prototype.moveFolder = function (payload) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- return __generator(this, function (_a) {
100
- return [2 /*return*/, this.client.post('/storage/move/folder', {
101
- folderId: payload.folderId,
102
- destination: payload.destinationFolderId,
103
- }, this.headers())];
104
- });
105
- });
106
- };
107
- /**
108
- * Moves a specific folder to a new location
109
- * @param payload
110
- */
111
- Storage.prototype.moveFolderByUuid = function (payload) {
112
- return __awaiter(this, void 0, void 0, function () {
113
- return __generator(this, function (_a) {
114
- return [2 /*return*/, this.client.patch("/folders/" + payload.folderUuid, {
115
- destinationFolder: payload.destinationFolderUuid,
116
- }, this.headers())];
117
- });
118
- });
119
- };
120
- /**
121
- * Updates the metadata of a folder
122
- * @param payload
123
- */
124
- Storage.prototype.updateFolder = function (payload) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0: return [4 /*yield*/, this.client.post("/storage/folder/" + payload.folderId + "/meta", {
129
- metadata: payload.changes,
130
- }, this.headers())];
131
- case 1:
132
- _a.sent();
133
- return [2 /*return*/];
134
- }
135
- });
136
- });
137
- };
138
- /**
139
- * Fetches & returns the contents of a specific folder
140
- * @param folderId
141
- */
142
- Storage.prototype.getFolderContent = function (folderId, trash) {
143
- if (trash === void 0) { trash = false; }
144
- var query = trash ? '/?trash=true' : '';
145
- var _a = this.client.getCancellable("/storage/v2/folder/" + folderId + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
146
- return [promise, requestCanceler];
147
- };
148
- /**
149
- * Returns metadata of a specific file
150
- * @param fileId
151
- */
152
- Storage.prototype.getFile = function (fileId) {
153
- var _a = this.client.getCancellable("/files/" + fileId + "/meta", this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
154
- return [promise, requestCanceler];
155
- };
156
- /**
157
- * Gets the files in a folder.
158
- *
159
- * @param {number} folderId - The ID of the folder.
160
- * @param {number} [offset=0] - The position of the first file to return.
161
- * @param {number} [limit=50] - The max number of files to be returned.
162
- * @param {string} [sort=plainName] - The reference column to sort it.
163
- * @param {string} [order=ASC] - The order to be followed.
164
- * @returns {[Promise<FetchPaginatedFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
165
- */
166
- Storage.prototype.getFolderFiles = function (folderId, offset, limit, sort, order) {
167
- if (offset === void 0) { offset = 0; }
168
- if (limit === void 0) { limit = 50; }
169
- if (sort === void 0) { sort = ''; }
170
- if (order === void 0) { order = ''; }
171
- var offsetQuery = "?offset=" + offset;
172
- var limitQuery = "&limit=" + limit;
173
- var sortQuery = sort !== '' ? "&sort=" + sort : '';
174
- var orderQuery = order !== '' ? "&order=" + order : '';
175
- var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
176
- var _a = this.client.getCancellable("folders/" + folderId + "/files/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
177
- return [promise, requestCanceler];
178
- };
179
- /**
180
- * Gets the files in a folder by its UUID.
181
- *
182
- * @param {UUID} folderUuid - The UUID of the folder.
183
- * @param {number} [offset=0] - The position of the first file to return.
184
- * @param {number} [limit=50] - The max number of files to be returned.
185
- * @param {string} [sort=plainName] - The reference column to sort it.
186
- * @param {string} [order=ASC] - The order to be followed.
187
- * @returns {[Promise<FetchPaginatedFilesContent>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
188
- */
189
- Storage.prototype.getFolderFilesByUuid = function (folderUuid, offset, limit, sort, order) {
190
- if (offset === void 0) { offset = 0; }
191
- if (limit === void 0) { limit = 50; }
192
- if (sort === void 0) { sort = ''; }
193
- if (order === void 0) { order = ''; }
194
- var offsetQuery = "?offset=" + offset;
195
- var limitQuery = "&limit=" + limit;
196
- var sortQuery = sort !== '' ? "&sort=" + sort : '';
197
- var orderQuery = order !== '' ? "&order=" + order : '';
198
- var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
199
- var _a = this.client.getCancellable("folders/content/" + folderUuid + "/files/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
200
- return [promise, requestCanceler];
201
- };
202
- /**
203
- * Gets the subfolders of a folder.
204
- *
205
- * @param {number} folderId - The ID of the folder.
206
- * @param {number} [offset=0] - The position of the first subfolder to return.
207
- * @param {number} [limit=50] - The max number of subfolders to return.
208
- * @param {string} [sort=plainName] - The reference column to sort it.
209
- * @param {string} [order=ASC] - The order to be followed.
210
- * @returns {[Promise<FetchPaginatedFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
211
- */
212
- Storage.prototype.getFolderFolders = function (folderId, offset, limit, sort, order) {
213
- if (offset === void 0) { offset = 0; }
214
- if (limit === void 0) { limit = 50; }
215
- if (sort === void 0) { sort = ''; }
216
- if (order === void 0) { order = ''; }
217
- var offsetQuery = "?offset=" + offset;
218
- var limitQuery = "&limit=" + limit;
219
- var sortQuery = sort !== '' ? "&sort=" + sort : '';
220
- var orderQuery = order !== '' ? "&order=" + order : '';
221
- var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
222
- var _a = this.client.getCancellable("folders/" + folderId + "/folders/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
223
- return [promise, requestCanceler];
224
- };
225
- /**
226
- * Gets the subfolders of a folder by its UUID.
227
- *
228
- * @param {UUID} folderUuid - The UUID of the folder.
229
- * @param {number} [offset=0] - The position of the first subfolder to return.
230
- * @param {number} [limit=50] - The max number of subfolders to return.
231
- * @param {string} [sort=plainName] - The reference column to sort it.
232
- * @param {string} [order=ASC] - The order to be followed.
233
- * @returns {[Promise<FetchPaginatedFoldersContent>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
234
- */
235
- Storage.prototype.getFolderFoldersByUuid = function (folderUuid, offset, limit, sort, order) {
236
- if (offset === void 0) { offset = 0; }
237
- if (limit === void 0) { limit = 50; }
238
- if (sort === void 0) { sort = ''; }
239
- if (order === void 0) { order = ''; }
240
- var offsetQuery = "?offset=" + offset;
241
- var limitQuery = "&limit=" + limit;
242
- var sortQuery = sort !== '' ? "&sort=" + sort : '';
243
- var orderQuery = order !== '' ? "&order=" + order : '';
244
- var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
245
- var _a = this.client.getCancellable("folders/content/" + folderUuid + "/folders/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
246
- return [promise, requestCanceler];
247
- };
248
- /**
249
- * Removes a specific folder from the centralized persistence
250
- * @param folderId
251
- */
252
- Storage.prototype.deleteFolder = function (folderId) {
253
- return this.client.delete("/storage/folder/" + folderId, this.headers());
254
- };
255
- /**
256
- * Returns the total size of a folder
257
- * @param folderId
258
- */
259
- Storage.prototype.getFolderSize = function (folderId) {
260
- return this.client
261
- .get("/storage/folder/size/" + folderId, this.headers())
262
- .then(function (response) {
263
- return response.size;
264
- });
265
- };
266
- /**
267
- * Creates a new file entry
268
- * @param fileEntry
269
- */
270
- Storage.prototype.createFileEntry = function (fileEntry, resourcesToken) {
271
- return this.client.post('/storage/file', {
272
- file: {
273
- fileId: fileEntry.id,
274
- type: fileEntry.type,
275
- bucket: fileEntry.bucket,
276
- size: fileEntry.size,
277
- folder_id: fileEntry.folder_id,
278
- name: fileEntry.name,
279
- plain_name: fileEntry.plain_name,
280
- encrypt_version: fileEntry.encrypt_version,
281
- },
282
- }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
283
- };
284
- /**
285
- * Creates a new thumbnail entry
286
- * @param thumbnailEntry
287
- */
288
- Storage.prototype.createThumbnailEntry = function (thumbnailEntry, resourcesToken) {
289
- return this.client.post('/storage/thumbnail', {
290
- thumbnail: thumbnailEntry,
291
- }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
292
- };
293
- /**
294
- * Updates the details of a file entry
295
- * @param payload
296
- */
297
- Storage.prototype.updateFile = function (payload, resourcesToken) {
298
- return this.client.post("/storage/file/" + payload.fileId + "/meta", {
299
- metadata: payload.metadata,
300
- bucketId: payload.bucketId,
301
- relativePath: payload.destinationPath,
302
- }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
303
- };
304
- /**
305
- * Deletes a specific file entry
306
- * @param payload
307
- */
308
- Storage.prototype.deleteFile = function (payload) {
309
- return this.client.delete("/storage/folder/" + payload.folderId + "/file/" + payload.fileId, this.headers());
310
- };
311
- /**
312
- * Updates the persisted path of a file entry
313
- * @param payload
314
- */
315
- Storage.prototype.moveFile = function (payload) {
316
- return this.client.post('/storage/move/file', {
317
- fileId: payload.fileId,
318
- destination: payload.destination,
319
- relativePath: payload.destinationPath,
320
- bucketId: payload.bucketId,
321
- }, this.headers());
322
- };
323
- /**
324
- * Moves a specific file to a new location
325
- * @param payload
326
- */
327
- Storage.prototype.moveFileByUuid = function (payload) {
328
- return __awaiter(this, void 0, void 0, function () {
329
- return __generator(this, function (_a) {
330
- return [2 /*return*/, this.client.patch("/files/" + payload.fileUuid, {
331
- destinationFolder: payload.destinationFolderUuid,
332
- }, this.headers())];
333
- });
334
- });
335
- };
336
- /**
337
- * Returns a list of the n most recent files
338
- * @param limit
339
- */
340
- Storage.prototype.getRecentFiles = function (limit) {
341
- return this.client.get("/storage/recents?limit=" + limit, this.headers());
342
- };
343
- /**
344
- * Returns a list of items in trash
345
- */
346
- Storage.prototype.getTrash = function () {
347
- var _a = this.client.getCancellable('/storage/trash', this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
348
- return [promise, requestCanceler];
349
- };
350
- /**
351
- * Add Items to Trash
352
- * @param payload
353
- */
354
- Storage.prototype.addItemsToTrash = function (payload) {
355
- return this.client.post('/storage/trash/add', {
356
- items: payload.items,
357
- }, this.headers());
358
- };
359
- /**
360
- * Returns a list of the n most recent files
361
- * @param limit
362
- */
363
- Storage.prototype.searchItemsByName = function (plain_name) {
364
- return this.client.post('/users/search', { plain_name: plain_name }, this.headers());
365
- };
366
- /**
367
- * Returns the current space usage of the user
368
- */
369
- Storage.prototype.spaceUsage = function () {
370
- return this.client.get('/usage', this.headers());
371
- };
372
- /**
373
- * Returns the current space limit for the user
374
- */
375
- Storage.prototype.spaceLimit = function () {
376
- return this.client.get('/limit', this.headers());
377
- };
378
- /**
379
- * Get global search items.
380
- *
381
- * @param {string} search - The name of the item.
382
- * @returns {[Promise<SearchResultData>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
383
- */
384
- Storage.prototype.getGlobalSearchItems = function (search) {
385
- var _a = this.client.getCancellable("fuzzy/" + search, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
386
- return [promise, requestCanceler];
387
- };
388
- /**
389
- * Returns the needed headers for the module requests
390
- * @private
391
- */
392
- Storage.prototype.headers = function () {
393
- return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, this.apiSecurity.token);
394
- };
395
- /**
396
- * Gets the ancestors of a given folder UUID
397
- *
398
- * @param {string} folderUUID - UUID of the folder.
399
- * @returns {Promise<FolderAncestor[]>}
400
- */
401
- Storage.prototype.getFolderAncestors = function (uuid) {
402
- return this.client.get("folders/" + uuid + "/ancestors", this.headers());
403
- };
404
- /**
405
- * Gets the meta of a given folder UUID
406
- *
407
- * @param {string} folderUUID - UUID of the folder.
408
- * @returns {Promise<FolderMeta>}
409
- */
410
- Storage.prototype.getFolderMeta = function (uuid) {
411
- return this.client.get("folders/" + uuid + "/meta", this.headers());
412
- };
413
- /**
414
- * Gets the meta of a given folder Id
415
- *
416
- * @param {number} folderId - Id of the folder.
417
- * @returns {Promise<FolderMeta>}
418
- */
419
- Storage.prototype.getFolderMetaById = function (folderId) {
420
- return this.client.get("folders/" + folderId + "/metadata", this.headers());
421
- };
422
- /**
423
- * Replaces a file with a new one.
424
- *
425
- * @param {string} uuid - UUID of the file.
426
- * @param {ReplaceFile} payload
427
- * @returns {Promise<DriveFileData>} - The replaced file data.
428
- */
429
- Storage.prototype.replaceFile = function (uuid, payload) {
430
- return this.client.put("/files/" + uuid, __assign({}, payload), this.headers());
431
- };
432
- return Storage;
433
- }());
434
- exports.Storage = Storage;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
41
+ var __generator = (this && this.__generator) || function (thisArg, body) {
42
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
+ function verb(n) { return function (v) { return step([n, v]); }; }
45
+ function step(op) {
46
+ if (f) throw new TypeError("Generator is already executing.");
47
+ while (_) try {
48
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
49
+ if (y = 0, t) op = [op[0] & 2, t.value];
50
+ switch (op[0]) {
51
+ case 0: case 1: t = op; break;
52
+ case 4: _.label++; return { value: op[1], done: false };
53
+ case 5: _.label++; y = op[1]; op = [0]; continue;
54
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
+ default:
56
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
+ if (t[2]) _.ops.pop();
61
+ _.trys.pop(); continue;
62
+ }
63
+ op = body.call(thisArg, _);
64
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
+ }
67
+ };
68
+ Object.defineProperty(exports, "__esModule", { value: true });
69
+ exports.Storage = exports.StorageTypes = void 0;
70
+ var headers_1 = require("../../shared/headers");
71
+ var client_1 = require("../../shared/http/client");
72
+ exports.StorageTypes = __importStar(require("./types"));
73
+ var Storage = /** @class */ (function () {
74
+ function Storage(apiUrl, appDetails, apiSecurity) {
75
+ this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
76
+ this.appDetails = appDetails;
77
+ this.apiSecurity = apiSecurity;
78
+ }
79
+ Storage.client = function (apiUrl, appDetails, apiSecurity) {
80
+ return new Storage(apiUrl, appDetails, apiSecurity);
81
+ };
82
+ /**
83
+ * Creates a new folder
84
+ * @param payload
85
+ */
86
+ Storage.prototype.createFolder = function (payload) {
87
+ var _a = this.client.postCancellable('/storage/folder', {
88
+ parentFolderId: payload.parentFolderId,
89
+ folderName: payload.folderName,
90
+ }, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
91
+ return [promise, requestCanceler];
92
+ };
93
+ /**
94
+ * Creates a new folder
95
+ * @param payload
96
+ */
97
+ Storage.prototype.createFolderByUuid = function (payload) {
98
+ var _a = this.client.postCancellable('/folders', {
99
+ plainName: payload.plainName,
100
+ parentFolderUuid: payload.parentFolderUuid,
101
+ }, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
102
+ return [promise, requestCanceler];
103
+ };
104
+ /**
105
+ * Moves a specific folder to a new location
106
+ * @param payload
107
+ */
108
+ Storage.prototype.moveFolder = function (payload) {
109
+ return __awaiter(this, void 0, void 0, function () {
110
+ return __generator(this, function (_a) {
111
+ return [2 /*return*/, this.client.post('/storage/move/folder', {
112
+ folderId: payload.folderId,
113
+ destination: payload.destinationFolderId,
114
+ }, this.headers())];
115
+ });
116
+ });
117
+ };
118
+ /**
119
+ * Moves a specific folder to a new location
120
+ * @param payload
121
+ */
122
+ Storage.prototype.moveFolderByUuid = function (payload) {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ return __generator(this, function (_a) {
125
+ return [2 /*return*/, this.client.patch("/folders/" + payload.folderUuid, {
126
+ destinationFolder: payload.destinationFolderUuid,
127
+ }, this.headers())];
128
+ });
129
+ });
130
+ };
131
+ /**
132
+ * Updates the metadata of a folder
133
+ * @param payload
134
+ */
135
+ Storage.prototype.updateFolder = function (payload) {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0: return [4 /*yield*/, this.client.post("/storage/folder/" + payload.folderId + "/meta", {
140
+ metadata: payload.changes,
141
+ }, this.headers())];
142
+ case 1:
143
+ _a.sent();
144
+ return [2 /*return*/];
145
+ }
146
+ });
147
+ });
148
+ };
149
+ /**
150
+ * Updates the name of a folder with the given UUID.
151
+ *
152
+ * @param {Object} payload - The payload containing the folder UUID and the new name.
153
+ * @param {string} payload.folderUuid - The UUID of the folder to update.
154
+ * @param {string} payload.name - The new name for the folder.
155
+ * @param {Token} [resourcesToken] - An optional token for authentication.
156
+ * @return {Promise<void>} A promise that resolves when the folder name is successfully updated.
157
+ */
158
+ Storage.prototype.updateFolderNameWithUUID = function (payload, resourcesToken) {
159
+ var folderUuid = payload.folderUuid, name = payload.name;
160
+ return this.client.put("/folders/" + folderUuid + "/meta", {
161
+ plainName: name,
162
+ }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
163
+ };
164
+ /**
165
+ * Fetches & returns the contents of a specific folder
166
+ * @param folderId
167
+ */
168
+ Storage.prototype.getFolderContent = function (folderId, trash) {
169
+ if (trash === void 0) { trash = false; }
170
+ var query = trash ? '/?trash=true' : '';
171
+ var _a = this.client.getCancellable("/storage/v2/folder/" + folderId + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
172
+ return [promise, requestCanceler];
173
+ };
174
+ /**
175
+ * Fetches and returns the contents of a specific folder by its UUID.
176
+ *
177
+ * @param {string} folderUuid - The UUID of the folder.
178
+ * @param {boolean} [trash=false] - Whether to include trash items in the response.
179
+ * @param {boolean} [offset] - The position of the first file to return.
180
+ * @param {boolean} [limit] - The max number of files to be returned.
181
+ * @param {boolean} [workspacesToken] - Token for accessing workspaces.
182
+ * @return {[Promise<FetchFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
183
+ */
184
+ Storage.prototype.getFolderContentByUuid = function (_a) {
185
+ var folderUuid = _a.folderUuid, _b = _a.trash, trash = _b === void 0 ? false : _b, offset = _a.offset, limit = _a.limit, workspacesToken = _a.workspacesToken;
186
+ var query = new URLSearchParams();
187
+ if (offset !== undefined)
188
+ query.set('offset', String(offset));
189
+ if (limit !== undefined)
190
+ query.set('limit', String(limit));
191
+ if (trash)
192
+ query.set('trash', 'true');
193
+ var customHeaders = workspacesToken
194
+ ? {
195
+ 'x-internxt-workspace': workspacesToken,
196
+ }
197
+ : undefined;
198
+ var _c = this.client.getCancellable("/folders/content/" + folderUuid + "?" + query, this.headers(customHeaders)), promise = _c.promise, requestCanceler = _c.requestCanceler;
199
+ return [promise, requestCanceler];
200
+ };
201
+ /**
202
+ * Retrieves a file with the specified fileId along with the associated workspacesToken.
203
+ *
204
+ * @param {string} fileId - The ID of the file to retrieve.
205
+ * @param {string} [workspacesToken] - Token for accessing workspaces.
206
+ * @return {[Promise<FileMeta>, RequestCanceler]} A promise with FileMeta and a canceler for the request.
207
+ */
208
+ Storage.prototype.getFile = function (fileId, workspacesToken) {
209
+ var customHeaders = workspacesToken
210
+ ? {
211
+ 'x-internxt-workspace': workspacesToken,
212
+ }
213
+ : undefined;
214
+ var _a = this.client.getCancellable("/files/" + fileId + "/meta", this.headers(customHeaders)), promise = _a.promise, requestCanceler = _a.requestCanceler;
215
+ return [promise, requestCanceler];
216
+ };
217
+ /**
218
+ * Gets the files in a folder.
219
+ *
220
+ * @param {number} folderId - The ID of the folder.
221
+ * @param {number} [offset=0] - The position of the first file to return.
222
+ * @param {number} [limit=50] - The max number of files to be returned.
223
+ * @param {string} [sort=plainName] - The reference column to sort it.
224
+ * @param {string} [order=ASC] - The order to be followed.
225
+ * @returns {[Promise<FetchPaginatedFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
226
+ */
227
+ Storage.prototype.getFolderFiles = function (folderId, offset, limit, sort, order) {
228
+ if (offset === void 0) { offset = 0; }
229
+ if (limit === void 0) { limit = 50; }
230
+ if (sort === void 0) { sort = ''; }
231
+ if (order === void 0) { order = ''; }
232
+ var offsetQuery = "?offset=" + offset;
233
+ var limitQuery = "&limit=" + limit;
234
+ var sortQuery = sort !== '' ? "&sort=" + sort : '';
235
+ var orderQuery = order !== '' ? "&order=" + order : '';
236
+ var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
237
+ var _a = this.client.getCancellable("folders/" + folderId + "/files/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
238
+ return [promise, requestCanceler];
239
+ };
240
+ /**
241
+ * Gets the files in a folder by its UUID.
242
+ *
243
+ * @param {UUID} folderUuid - The UUID of the folder.
244
+ * @param {number} [offset=0] - The position of the first file to return.
245
+ * @param {number} [limit=50] - The max number of files to be returned.
246
+ * @param {string} [sort=plainName] - The reference column to sort it.
247
+ * @param {string} [order=ASC] - The order to be followed.
248
+ * @returns {[Promise<FetchPaginatedFilesContent>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
249
+ */
250
+ Storage.prototype.getFolderFilesByUuid = function (folderUuid, offset, limit, sort, order) {
251
+ if (offset === void 0) { offset = 0; }
252
+ if (limit === void 0) { limit = 50; }
253
+ if (sort === void 0) { sort = ''; }
254
+ if (order === void 0) { order = ''; }
255
+ var offsetQuery = "?offset=" + offset;
256
+ var limitQuery = "&limit=" + limit;
257
+ var sortQuery = sort !== '' ? "&sort=" + sort : '';
258
+ var orderQuery = order !== '' ? "&order=" + order : '';
259
+ var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
260
+ var _a = this.client.getCancellable("folders/content/" + folderUuid + "/files/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
261
+ return [promise, requestCanceler];
262
+ };
263
+ /**
264
+ * Gets the subfolders of a folder.
265
+ *
266
+ * @param {number} folderId - The ID of the folder.
267
+ * @param {number} [offset=0] - The position of the first subfolder to return.
268
+ * @param {number} [limit=50] - The max number of subfolders to return.
269
+ * @param {string} [sort=plainName] - The reference column to sort it.
270
+ * @param {string} [order=ASC] - The order to be followed.
271
+ * @returns {[Promise<FetchPaginatedFolderContentResponse>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
272
+ */
273
+ Storage.prototype.getFolderFolders = function (folderId, offset, limit, sort, order) {
274
+ if (offset === void 0) { offset = 0; }
275
+ if (limit === void 0) { limit = 50; }
276
+ if (sort === void 0) { sort = ''; }
277
+ if (order === void 0) { order = ''; }
278
+ var offsetQuery = "?offset=" + offset;
279
+ var limitQuery = "&limit=" + limit;
280
+ var sortQuery = sort !== '' ? "&sort=" + sort : '';
281
+ var orderQuery = order !== '' ? "&order=" + order : '';
282
+ var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
283
+ var _a = this.client.getCancellable("folders/" + folderId + "/folders/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
284
+ return [promise, requestCanceler];
285
+ };
286
+ /**
287
+ * Gets the subfolders of a folder by its UUID.
288
+ *
289
+ * @param {UUID} folderUuid - The UUID of the folder.
290
+ * @param {number} [offset=0] - The position of the first subfolder to return.
291
+ * @param {number} [limit=50] - The max number of subfolders to return.
292
+ * @param {string} [sort=plainName] - The reference column to sort it.
293
+ * @param {string} [order=ASC] - The order to be followed.
294
+ * @returns {[Promise<FetchPaginatedFoldersContent>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
295
+ */
296
+ Storage.prototype.getFolderFoldersByUuid = function (folderUuid, offset, limit, sort, order) {
297
+ if (offset === void 0) { offset = 0; }
298
+ if (limit === void 0) { limit = 50; }
299
+ if (sort === void 0) { sort = ''; }
300
+ if (order === void 0) { order = ''; }
301
+ var offsetQuery = "?offset=" + offset;
302
+ var limitQuery = "&limit=" + limit;
303
+ var sortQuery = sort !== '' ? "&sort=" + sort : '';
304
+ var orderQuery = order !== '' ? "&order=" + order : '';
305
+ var query = "" + offsetQuery + limitQuery + sortQuery + orderQuery;
306
+ var _a = this.client.getCancellable("folders/content/" + folderUuid + "/folders/" + query, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
307
+ return [promise, requestCanceler];
308
+ };
309
+ /**
310
+ * Removes a specific folder from the centralized persistence
311
+ * @param folderId
312
+ */
313
+ Storage.prototype.deleteFolder = function (folderId) {
314
+ return this.client.delete("/storage/folder/" + folderId, this.headers());
315
+ };
316
+ /**
317
+ * Returns the total size of a folder
318
+ * @param folderId
319
+ */
320
+ Storage.prototype.getFolderSize = function (folderId) {
321
+ return this.client
322
+ .get("/storage/folder/size/" + folderId, this.headers())
323
+ .then(function (response) {
324
+ return response.size;
325
+ });
326
+ };
327
+ /**
328
+ * Creates a new file entry
329
+ * @param fileEntry
330
+ */
331
+ Storage.prototype.createFileEntry = function (fileEntry, resourcesToken) {
332
+ return this.client.post('/storage/file', {
333
+ file: {
334
+ fileId: fileEntry.id,
335
+ type: fileEntry.type,
336
+ bucket: fileEntry.bucket,
337
+ size: fileEntry.size,
338
+ folder_id: fileEntry.folder_id,
339
+ name: fileEntry.name,
340
+ plain_name: fileEntry.plain_name,
341
+ encrypt_version: fileEntry.encrypt_version,
342
+ },
343
+ }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
344
+ };
345
+ /**
346
+ * Creates a new file entry
347
+ * @param fileEntry
348
+ */
349
+ Storage.prototype.createFileEntryByUuid = function (fileEntry, resourcesToken) {
350
+ return this.client.post('/files', {
351
+ name: fileEntry.name,
352
+ bucket: fileEntry.bucket,
353
+ fileId: fileEntry.id,
354
+ encryptVersion: fileEntry.encrypt_version,
355
+ folderUuid: fileEntry.folder_id,
356
+ size: fileEntry.size,
357
+ plainName: fileEntry.plain_name,
358
+ type: fileEntry.type,
359
+ }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
360
+ };
361
+ /**
362
+ * Creates a new thumbnail entry
363
+ * @param thumbnailEntry
364
+ */
365
+ Storage.prototype.createThumbnailEntry = function (thumbnailEntry, resourcesToken) {
366
+ return this.client.post('/storage/thumbnail', {
367
+ thumbnail: thumbnailEntry,
368
+ }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
369
+ };
370
+ /**
371
+ * Updates the details of a file entry
372
+ * @param payload
373
+ */
374
+ Storage.prototype.updateFile = function (payload, resourcesToken) {
375
+ return this.client.post("/storage/file/" + payload.fileId + "/meta", {
376
+ metadata: payload.metadata,
377
+ bucketId: payload.bucketId,
378
+ relativePath: payload.destinationPath,
379
+ }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
380
+ };
381
+ /**
382
+ * Updates the name of a file with the given UUID.
383
+ *
384
+ * @param {Object} payload - The payload containing the UUID and new name of the file.
385
+ * @param {string} payload.fileUuid - The UUID of the file.
386
+ * @param {string} payload.name - The new name of the file.
387
+ * @param {string} [resourcesToken] - The token for accessing resources.
388
+ * @return {Promise<void>} - A Promise that resolves when the file name is successfully updated.
389
+ */
390
+ Storage.prototype.updateFileNameWithUUID = function (payload, resourcesToken) {
391
+ var fileUuid = payload.fileUuid, name = payload.name;
392
+ return this.client.put("/files/" + fileUuid + "/meta", {
393
+ plainName: name,
394
+ }, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
395
+ };
396
+ /**
397
+ * Updates the name and the type from a given file UUID.
398
+ *
399
+ * @param {Object} payload - The payload containing the UUID and the new properties of the file.
400
+ * @param {string} payload.fileUuid - The UUID of the file.
401
+ * @param {string} payload.name - The new name of the file.
402
+ * @param {string} payload.type - The new type of the file.
403
+ * @param {string} [resourcesToken] - The token for accessing resources.
404
+ * @return {Promise<void>} - A Promise that resolves when the file name is successfully updated.
405
+ */
406
+ Storage.prototype.updateFileMetaByUUID = function (fileUuid, payload, resourcesToken) {
407
+ return this.client.put("/files/" + fileUuid + "/meta", payload, (0, headers_1.addResourcesTokenToHeaders)(this.headers(), resourcesToken));
408
+ };
409
+ /**
410
+ * Deletes a specific file entry
411
+ * @param payload
412
+ */
413
+ Storage.prototype.deleteFile = function (payload) {
414
+ return this.client.delete("/storage/folder/" + payload.folderId + "/file/" + payload.fileId, this.headers());
415
+ };
416
+ /**
417
+ * Updates the persisted path of a file entry
418
+ * @param payload
419
+ */
420
+ Storage.prototype.moveFile = function (payload) {
421
+ return this.client.post('/storage/move/file', {
422
+ fileId: payload.fileId,
423
+ destination: payload.destination,
424
+ relativePath: payload.destinationPath,
425
+ bucketId: payload.bucketId,
426
+ }, this.headers());
427
+ };
428
+ /**
429
+ * Moves a specific file to a new location
430
+ * @param payload
431
+ */
432
+ Storage.prototype.moveFileByUuid = function (payload) {
433
+ return __awaiter(this, void 0, void 0, function () {
434
+ return __generator(this, function (_a) {
435
+ return [2 /*return*/, this.client.patch("/files/" + payload.fileUuid, {
436
+ destinationFolder: payload.destinationFolderUuid,
437
+ }, this.headers())];
438
+ });
439
+ });
440
+ };
441
+ /**
442
+ * Returns a list of the n most recent files
443
+ * @param limit
444
+ * @deprecated use `getRecentFilesV2` call instead.
445
+ */
446
+ Storage.prototype.getRecentFiles = function (limit) {
447
+ return this.client.get("/storage/recents?limit=" + limit, this.headers());
448
+ };
449
+ /**
450
+ * Returns a list of the n most recent files
451
+ * @param limit
452
+ */
453
+ Storage.prototype.getRecentFilesV2 = function (limit) {
454
+ return __awaiter(this, void 0, void 0, function () {
455
+ return __generator(this, function (_a) {
456
+ return [2 /*return*/, this.client.get("/files/recents?limit=" + limit, this.headers())];
457
+ });
458
+ });
459
+ };
460
+ /**
461
+ * Returns a list of items in trash
462
+ */
463
+ Storage.prototype.getTrash = function () {
464
+ var _a = this.client.getCancellable('/storage/trash', this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
465
+ return [promise, requestCanceler];
466
+ };
467
+ /**
468
+ * Add Items to Trash
469
+ * @param payload
470
+ */
471
+ Storage.prototype.addItemsToTrash = function (payload) {
472
+ return this.client.post('/storage/trash/add', {
473
+ items: payload.items,
474
+ }, this.headers());
475
+ };
476
+ /**
477
+ * Returns a list of the n most recent files
478
+ * @param limit
479
+ */
480
+ Storage.prototype.searchItemsByName = function (plain_name) {
481
+ return this.client.post('/users/search', { plain_name: plain_name }, this.headers());
482
+ };
483
+ /**
484
+ * Returns the current space usage of the user
485
+ */
486
+ Storage.prototype.spaceUsage = function () {
487
+ return this.client.get('/usage', this.headers());
488
+ };
489
+ /**
490
+ * Returns the current space limit for the user
491
+ */
492
+ Storage.prototype.spaceLimit = function () {
493
+ return this.client.get('/limit', this.headers());
494
+ };
495
+ /**
496
+ * Get global search items.
497
+ *
498
+ * @param {string} search - The name of the item.
499
+ * @param {string} workspaceId - The ID of the workspace (optional).
500
+ * @returns {[Promise<SearchResultData>, RequestCanceler]} An array containing a promise to get the API response and a function to cancel the request.
501
+ */
502
+ Storage.prototype.getGlobalSearchItems = function (search, workspaceId) {
503
+ var _a = workspaceId
504
+ ? this.client.getCancellable("workspaces/" + workspaceId + "/fuzzy/" + search, this.headers())
505
+ : this.client.getCancellable("fuzzy/" + search, this.headers()), promise = _a.promise, requestCanceler = _a.requestCanceler;
506
+ return [promise, requestCanceler];
507
+ };
508
+ /**
509
+ * Returns the needed headers for the module requests
510
+ * @private
511
+ */
512
+ Storage.prototype.headers = function (customHeaders) {
513
+ var _a;
514
+ return (0, headers_1.headersWithToken)(this.appDetails.clientName, this.appDetails.clientVersion, this.apiSecurity.token, (_a = this.apiSecurity) === null || _a === void 0 ? void 0 : _a.workspaceToken, customHeaders);
515
+ };
516
+ /**
517
+ * Gets the ancestors of a given folder UUID
518
+ *
519
+ * @param {string} uuid - UUID of the folder.
520
+ * @param {boolean} [isShared=false] - Whether the folder is a shared item or not.
521
+ * @returns {Promise<FolderAncestor[]>} A promise that resolves with an array of ancestors of the given folder.
522
+ */
523
+ Storage.prototype.getFolderAncestors = function (uuid, isShared) {
524
+ if (isShared === void 0) { isShared = false; }
525
+ return this.client.get("folders/" + uuid + "/ancestors?isSharedItem=" + isShared, this.headers());
526
+ };
527
+ /**
528
+ * Gets the meta of a given folder UUID
529
+ *
530
+ * @param {string} folderUUID - UUID of the folder.
531
+ * @returns {Promise<FolderMeta>}
532
+ */
533
+ Storage.prototype.getFolderMeta = function (uuid, workspacesToken, resourcesToken) {
534
+ var customHeaders = workspacesToken
535
+ ? {
536
+ 'x-internxt-workspace': workspacesToken,
537
+ }
538
+ : undefined;
539
+ return this.client.get("folders/" + uuid + "/meta", (0, headers_1.addResourcesTokenToHeaders)(this.headers(customHeaders), resourcesToken));
540
+ };
541
+ /**
542
+ * Gets the meta of a given folder Id
543
+ *
544
+ * @param {number} folderId - Id of the folder.
545
+ * @returns {Promise<FolderMeta>}
546
+ */
547
+ Storage.prototype.getFolderMetaById = function (folderId) {
548
+ return this.client.get("folders/" + folderId + "/metadata", this.headers());
549
+ };
550
+ /**
551
+ * Replaces a file with a new one.
552
+ *
553
+ * @param {string} uuid - UUID of the file.
554
+ * @param {ReplaceFile} payload
555
+ * @returns {Promise<DriveFileData>} - The replaced file data.
556
+ */
557
+ Storage.prototype.replaceFile = function (uuid, payload) {
558
+ return this.client.put("/files/" + uuid, __assign({}, payload), this.headers());
559
+ };
560
+ /**
561
+ * Checks the size limit for a file.
562
+ *
563
+ * @param {number} size - The size of the file to check.
564
+ * @return {Promise<void>} - A promise that resolves when the size limit check is complete.
565
+ */
566
+ Storage.prototype.checkSizeLimit = function (size) {
567
+ return __awaiter(this, void 0, void 0, function () {
568
+ return __generator(this, function (_a) {
569
+ return [2 /*return*/, this.client.post('/files/check-size-limit', {
570
+ file: {
571
+ size: size,
572
+ },
573
+ }, this.headers())];
574
+ });
575
+ });
576
+ };
577
+ /**
578
+ * Retrieves the folder tree based on the UUID.
579
+ *
580
+ * @param {string} uuid - The UUID of the folder.
581
+ * @return {Promise<FolderTreeResponse>} The promise containing the folder tree response.
582
+ */
583
+ Storage.prototype.getFolderTree = function (uuid) {
584
+ return this.client.get("/folders/" + uuid + "/tree", this.headers());
585
+ };
586
+ /**
587
+ * Checks if the given files already exist in the given folder.
588
+ *
589
+ * @param {CheckDuplicatedFilesPayload} payload - Payload containing the folder UUID and the list of files to check.
590
+ * @return {Promise<CheckDuplicatedFilesResponse>} - Promise that contains the duplicated files in a list.
591
+ */
592
+ Storage.prototype.checkDuplicatedFiles = function (_a) {
593
+ var folderUuid = _a.folderUuid, filesList = _a.filesList;
594
+ return this.client.post("/folders/content/" + folderUuid + "/files/existence", {
595
+ files: filesList,
596
+ }, this.headers());
597
+ };
598
+ /**
599
+ * Checks if the given folders names already exist in the given folder
600
+ *
601
+ * @param {CheckDuplicatedFolderPayload} payload - Payload containing the folder UUID and the list of folders to check.
602
+ * @return {Promise<CheckDuplicatedFoldersResponse>} - Promise that contains the duplicated folders in a list.
603
+ */
604
+ Storage.prototype.checkDuplicatedFolders = function (_a) {
605
+ var folderUuid = _a.folderUuid, folderNamesList = _a.folderNamesList;
606
+ return this.client.post("/folders/content/" + folderUuid + "/folders/existence", {
607
+ plainNames: folderNamesList,
608
+ }, this.headers());
609
+ };
610
+ /**
611
+ * Gets the folder meta from a given path (e.g. "/folder1/folder2")
612
+ *
613
+ * @param {string} folderPath - The path of the folder.
614
+ * @returns {Promise<FolderMeta>} A promise that resolves the folder on that path.
615
+ */
616
+ Storage.prototype.getFolderByPath = function (folderPath) {
617
+ return this.client.get("folders/meta?path=" + folderPath, this.headers());
618
+ };
619
+ /**
620
+ * Gets the file meta from a given path (e.g. "/folder1/folder2/file.png")
621
+ *
622
+ * @param {string} filePath - The path of the file.
623
+ * @returns {Promise<FileMeta>} A promise that resolves the file on that path.
624
+ */
625
+ Storage.prototype.getFileByPath = function (filePath) {
626
+ return this.client.get("files/meta?path=" + filePath, this.headers());
627
+ };
628
+ return Storage;
629
+ }());
630
+ exports.Storage = Storage;