@internxt/sdk 1.5.25 → 1.6.4

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