files.com 1.2.136 → 1.2.138

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -77,13 +77,13 @@ access to the entire API. If the user is not an administrator, you will only be
77
77
  that user can access, and no access will be granted to site administration functions in the API.
78
78
 
79
79
  ```javascript title="Example Request"
80
- Files.setApiKey('YOUR_API_KEY')
80
+ Files.setApiKey('YOUR_API_KEY');
81
81
 
82
82
  // Alternatively, you can specify the API key on a per-object basis in the second parameter to a model constructor.
83
- const user = new User(params, { apiKey: 'YOUR_API_KEY' })
83
+ const user = new User(params, { apiKey: 'YOUR_API_KEY' });
84
84
 
85
85
  // You may also specify the API key on a per-request basis in the final parameter to static methods.
86
- await User.find(id, params, { apiKey: 'YOUR_API_KEY' })
86
+ await User.find(id, params, { apiKey: 'YOUR_API_KEY' });
87
87
  ```
88
88
 
89
89
  Don't forget to replace the placeholder, `YOUR_API_KEY`, with your actual API key.
@@ -108,7 +108,7 @@ password.
108
108
  This returns a session object that can be used to authenticate SDK method calls.
109
109
 
110
110
  ```javascript title="Example Request"
111
- const session = await Session.create({ username: 'motor', password: 'vroom' })
111
+ const session = await Session.create({ username: 'motor', password: 'vroom' });
112
112
  ```
113
113
 
114
114
  #### Using a Session
@@ -117,13 +117,13 @@ Once a session has been created, you can store the session globally, use the ses
117
117
 
118
118
  ```javascript title="Example Request"
119
119
  // You may set the returned session ID to be used by default for subsequent requests.
120
- Files.setSessionId(session.id)
120
+ Files.setSessionId(session.id);
121
121
 
122
122
  // Alternatively, you can specify the session ID on a per-object basis in the second parameter to a model constructor.
123
- const user = new User(params, { session_id: session.id })
123
+ const user = new User(params, { session_id: session.id });
124
124
 
125
125
  // You may also specify the session ID on a per-request basis in the final parameter to static methods.
126
- await User.find(id, params, { session_id: session.id })
126
+ await User.find(id, params, { session_id: session.id });
127
127
  ```
128
128
 
129
129
  #### Logging Out
@@ -131,7 +131,7 @@ await User.find(id, params, { session_id: session.id })
131
131
  User sessions can be ended calling the `destroy` method on the `session` object.
132
132
 
133
133
  ```javascript title="Example Request"
134
- await Session.destroy()
134
+ await Session.destroy();
135
135
  ```
136
136
 
137
137
  ## Configuration
@@ -158,8 +158,9 @@ Supported values:
158
158
  * LogLevel.DEBUG
159
159
 
160
160
  ```javascript title="Example setting"
161
- import { LogLevel } from 'files.com/lib/Logger.js'
162
- Files.setLogLevel(LogLevel.INFO)
161
+ import { LogLevel } from 'files.com/lib/Logger.js';
162
+
163
+ Files.setLogLevel(LogLevel.INFO);
163
164
  ```
164
165
 
165
166
  #### Debugging
@@ -170,7 +171,7 @@ Enable debug logging of API requests and/or response headers. Both settings defa
170
171
  Files.configureDebugging({
171
172
  debugRequest: true,
172
173
  debugResponseHeaders: true,
173
- })
174
+ });
174
175
  ```
175
176
 
176
177
  #### Network Settings
@@ -191,114 +192,112 @@ Files.configureNetwork({
191
192
 
192
193
  // auto-fetch all pages when results span multiple pages (default: `true`)
193
194
  autoPaginate: true,
194
- })
195
+ });
195
196
  ```
196
197
 
197
198
  ## Sort and Filter
198
199
 
199
- Several of the Files.com API resources have list operations that return multiple instances of the resource. The List operations
200
- can be sorted and filtered.
200
+ Several of the Files.com API resources have list operations that return multiple instances of the
201
+ resource. The List operations can be sorted and filtered.
201
202
 
202
203
  ### Sorting
203
204
 
204
- The returned data can be sorted by passing in the ```sort_by``` method argument.
205
-
206
- Each resource has a set of valid fields for sorting and can be sorted by one field at a time.
207
-
208
- The argument value is a Javascript object that has a property of the resource field name sort on and a value of either ```"asc"``` or ```"desc"``` to specify the sort order.
209
-
210
- ### Filters
211
-
212
- Filters apply selection criteria to the underlying query that returns the results. Filters can be applied individually to select resource fields
213
- and/or in a combination with each other. The results of applying filters and filter combinations can be sorted by a single field.
214
-
215
- The passed in argument value is a Javascript object that has a property of the resource field name to filter on and a passed in value to use in the filter comparison.
216
-
217
- Each resource has their own set of valid filters and fields, valid combinations of filters, and sortable fields.
205
+ To sort the returned data, pass in the ```sort_by``` method argument.
218
206
 
219
- #### Types of Filters
207
+ Each resource supports a unique set of valid sort fields and can only be sorted by one field at a
208
+ time.
220
209
 
221
- ##### Exact Filter
210
+ The argument value is a Javascript object that has a property of the resource field name sort on and
211
+ a value of either ```"asc"``` or ```"desc"``` to specify the sort order.
222
212
 
223
- `filter` - find resources that have an exact field value match to a passed in value. (i.e., FIELD_VALUE = PASS_IN_VALUE).
213
+ ```javascript title="Sort Example"
214
+ Files.setApiKey('my-key');
224
215
 
225
- #### Range Filters
216
+ // Users, sorted by username in ascending order.
217
+ const users = await User.list({
218
+ sort_by: { username: "asc"}
219
+ });
226
220
 
227
- `filter_gt` - find resources that have a field value that is greater than the passed in value. (i.e., FIELD_VALUE > PASS_IN_VALUE).
221
+ users.forEach(user => {
222
+ console.log(user.username);
223
+ });
224
+ ```
228
225
 
229
- `filter_gte` - find resources that have a field value that is greater than or equal to the passed in value. (i.e., FIELD_VALUE >= PASS_IN_VALUE).
226
+ ### Filtering
230
227
 
231
- `filter_lt` - find resources that have a field value that is less than the passed in value. (i.e., FIELD_VALUE < PASS_IN_VALUE).
228
+ Filters apply selection criteria to the underlying query that returns the results. They can be
229
+ applied individually or combined with other filters, and the resulting data can be sorted by a
230
+ single field.
232
231
 
233
- `filter_lte` - find resources that have a field value that is less than or equal to the passed in value. (i.e., FIELD_VALUE \<= PASS_IN_VALUE).
232
+ Each resource supports a unique set of valid filter fields, filter combinations, and combinations of
233
+ filters and sort fields.
234
234
 
235
- ##### Pattern Filter
235
+ The passed in argument value is a Javascript object that has a property of the resource field name
236
+ to filter on and a passed in value to use in the filter comparison.
236
237
 
237
- `filter_prefix` - find resources where the specified field is prefixed by the supplied value. This is applicable to values that are strings.
238
+ #### Filter Types
238
239
 
239
- ```javascript title="Sort Example"
240
- // users sorted by username
241
- Files.setApiKey('my-key');
242
- var users = await User.list({
243
- sort_by: { username: "asc"}
244
- })
245
-
246
- for (var i = 0; i < users.length; i++) {
247
- console.log(users[i].username);
248
- }
249
- ```
240
+ | Filter | Type | Description |
241
+ | --------- | --------- | --------- |
242
+ | `filter` | Exact | Find resources that have an exact field value match to a passed in value. (i.e., FIELD_VALUE = PASS_IN_VALUE). |
243
+ | `filter_prefix` | Pattern | Find resources where the specified field is prefixed by the supplied value. This is applicable to values that are strings. |
244
+ | `filter_gt` | Range | Find resources that have a field value that is greater than the passed in value. (i.e., FIELD_VALUE > PASS_IN_VALUE). |
245
+ | `filter_gteq` | Range | Find resources that have a field value that is greater than or equal to the passed in value. (i.e., FIELD_VALUE >= PASS_IN_VALUE). |
246
+ | `filter_lt` | Range | Find resources that have a field value that is less than the passed in value. (i.e., FIELD_VALUE < PASS_IN_VALUE). |
247
+ | `filter_lteq` | Range | Find resources that have a field value that is less than or equal to the passed in value. (i.e., FIELD_VALUE \<= PASS_IN_VALUE). |
250
248
 
251
249
  ```javascript title="Exact Filter Example"
252
- // non admin users
253
250
  Files.setApiKey('my-key');
254
- var users = await User.list({
255
- filter: { not_site_admin: true },
256
- sort_by: { username: "asc"}
257
- })
258
251
 
259
- for (var i = 0; i < users.length; i++) {
260
- console.log(users[i].username);
261
- }
252
+ // Users who are not site admins.
253
+ const users = await User.list({
254
+ filter: { not_site_admin: true }
255
+ });
256
+
257
+ users.forEach(user => {
258
+ console.log(user.username);
259
+ });
262
260
  ```
263
261
 
264
262
  ```javascript title="Range Filter Example"
265
- // users who haven't logged in since 2024-01-01
266
263
  Files.setApiKey('my-key');
267
- var users = await User.list({
268
- filter_gte: { last_login_at: "2024-01-01" },
269
- sort_by: { last_login_at: "asc"}
270
- })
271
264
 
272
- for (var i = 0; i < users.length; i++) {
273
- console.log(users[i].username);
274
- }
265
+ // Users who haven't logged in since 2024-01-01.
266
+ const users = await User.list({
267
+ filter_gteq: { last_login_at: "2024-01-01" }
268
+ });
269
+
270
+ users.forEach(user => {
271
+ console.log(user.username);
272
+ });
275
273
  ```
276
274
 
277
275
  ```javascript title="Pattern Filter Example"
278
- // users who usernames start with 'test'
279
276
  Files.setApiKey('my-key');
280
- var users = await User.list({
281
- filter_prefix: { username: "test" },
282
- sort_by: { last_login_at: "asc"}
283
- })
284
277
 
285
- for (var i = 0; i < users.length; i++) {
286
- console.log(users[i].username);
287
- }
278
+ // Users whose usernames start with 'test'.
279
+ const users = await User.list({
280
+ filter_prefix: { username: "test" }
281
+ });
282
+
283
+ users.forEach(user => {
284
+ console.log(user.username);
285
+ });
288
286
  ```
289
287
 
290
- ```javascript title="Combined Filter Example"
291
- // users who usernames start with 'test' and are not admins
288
+ ```javascript title="Combination Filter with Sort Example"
292
289
  Files.setApiKey('my-key');
293
- var users = await User.list({
294
- filter_prefix: { username: "test" },
295
- filter: { not_site_admin: true },
296
- sort_by: { last_login_at: "asc"}
297
- })
298
-
299
- for (var i = 0; i < users.length; i++) {
300
- console.log(users[i].username);
301
- }
290
+
291
+ // Users whose usernames start with 'test' and are not site admins, sorted by last login date.
292
+ const users = await User.list({
293
+ filter_prefix: { username: "test" },
294
+ filter: { not_site_admin: true },
295
+ sort_by: { last_login_at: "asc" }
296
+ });
297
+
298
+ users.forEach(user => {
299
+ console.log(user.username);
300
+ });
302
301
  ```
303
302
 
304
303
  ## Errors
@@ -319,20 +318,19 @@ Use standard Javascript exception handling to detect and deal with errors. It i
319
318
  catch the general `FilesError` exception as a catch-all.
320
319
 
321
320
  ```javascript title="Example Error Handling"
322
- import Session from 'files.com/lib/models/Session.js'
323
- import * as FilesErrors from 'files.com/lib/Errors.js'
321
+ import Session from 'files.com/lib/models/Session.js';
322
+ import * as FilesErrors from 'files.com/lib/Errors.js';
324
323
 
325
324
  try {
326
- const session = await Session.create({ username: 'USERNAME', password: 'BADPASSWORD' })
327
- }
328
- catch(err) {
329
- if (err instanceof FilesErrors.NotAuthenticatedError) {
330
- console.log("Authorization Error Occurred (" + err.constructor.name + "): " + err.error);
331
- } else if (err instanceof FilesErrors.FilesError) {
332
- console.log("Unknown Error Occurred (" + err.constructor.name + "): " + err.error);
333
- } else {
334
- throw err;
335
- }
325
+ const session = await Session.create({ username: 'USERNAME', password: 'BADPASSWORD' });
326
+ } catch(err) {
327
+ if (err instanceof FilesErrors.NotAuthenticatedError) {
328
+ console.error(`Authorization Error Occurred (${err.constructor.name}): ${err.error}`);
329
+ } else if (err instanceof FilesErrors.FilesError) {
330
+ console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
331
+ } else {
332
+ throw err;
333
+ }
336
334
  }
337
335
  ```
338
336
 
@@ -554,22 +552,23 @@ Error
554
552
  #### List Root Folder
555
553
 
556
554
  ```javascript
557
- import Folder from 'files.com/lib/models/Folder.js'
558
- const dirFiles = await Folder.listFor('/')
555
+ import Folder from 'files.com/lib/models/Folder.js';
556
+
557
+ const dirFiles = await Folder.listFor('/');
559
558
  ```
560
559
 
561
560
  #### Uploading a File
562
561
 
563
562
  ```javascript
564
- import File from 'files.com/lib/models/File.js'
565
- import { isBrowser } from 'files.com/lib/utils.js'
563
+ import File from 'files.com/lib/models/File.js';
564
+ import { isBrowser } from 'files.com/lib/utils.js';
566
565
 
567
566
  // uploading raw file data
568
- await File.uploadData(destinationFileName, data)
567
+ await File.uploadData(destinationFileName, data);
569
568
 
570
569
  // uploading a file on disk (not available in browser)
571
570
  if (!isBrowser()) {
572
- await File.uploadFile(destinationFileName, sourceFilePath)
571
+ await File.uploadFile(destinationFileName, sourceFilePath);
573
572
  }
574
573
  ```
575
574
 
@@ -578,26 +577,26 @@ if (!isBrowser()) {
578
577
  ##### Get a Downloadable File Object by Path
579
578
 
580
579
  ```javascript
581
- import File from 'files.com/lib/models/File.js'
580
+ import File from 'files.com/lib/models/File.js';
582
581
 
583
- const foundFile = await File.find(remoteFilePath)
584
- const downloadableFile = await foundFile.download()
582
+ const foundFile = await File.find(remoteFilePath);
583
+ const downloadableFile = await foundFile.download();
585
584
  ```
586
585
 
587
586
  ##### Download a File (not available in browser)
588
587
 
589
588
  ```javascript
590
- import { isBrowser } from 'files.com/lib/utils.js'
589
+ import { isBrowser } from 'files.com/lib/utils.js';
591
590
 
592
591
  if (!isBrowser()) {
593
592
  // download to a file on disk
594
- await downloadableFile.downloadToFile(localFilePath)
593
+ await downloadableFile.downloadToFile(localFilePath);
595
594
 
596
595
  // download to a writable stream
597
- await downloadableFile.downloadToStream(stream)
596
+ await downloadableFile.downloadToStream(stream);
598
597
 
599
598
  // download in memory and return as a UTF-8 string
600
- const textContent = await downloadableFile.downloadToString()
599
+ const textContent = await downloadableFile.downloadToString();
601
600
  }
602
601
  ```
603
602
 
@@ -606,7 +605,7 @@ if (!isBrowser()) {
606
605
  For related documentation see [Case Sensitivity Documentation](https://www.files.com/docs/files-and-folders/file-system-semantics/case-sensitivity).
607
606
 
608
607
  ```javascript
609
- import { pathNormalizer } from 'files.com/lib/utils.js'
608
+ import { pathNormalizer } from 'files.com/lib/utils.js';
610
609
 
611
610
  if (pathNormalizer.same('Fïłèńämê.Txt', 'filename.txt')) {
612
611
  // the paths are the same
package/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.136
1
+ 1.2.138
@@ -56,8 +56,8 @@ await Permission.list({
56
56
 
57
57
  ```
58
58
  await Permission.create({
59
+ 'path': "path",
59
60
  'group_id': 1,
60
- 'path': "example",
61
61
  'permission': "full",
62
62
  'recursive': true,
63
63
  'user_id': 1,
@@ -68,9 +68,9 @@ await Permission.create({
68
68
 
69
69
  ### Parameters
70
70
 
71
+ * `path` (string): Required - Folder path
71
72
  * `group_id` (int64): Group ID
72
- * `path` (string): Folder path
73
- * `permission` (string): Permission type. Can be `admin`, `full`, `readonly`, `writeonly`, `list`, or `history`
73
+ * `permission` (string): Permission type. Can be `admin`, `full`, `readonly`, `writeonly`, `list`, or `history`
74
74
  * `recursive` (boolean): Apply to subfolders recursively?
75
75
  * `user_id` (int64): User ID. Provide `username` or `user_id`
76
76
  * `username` (string): User username. Provide `username` or `user_id`
package/lib/Files.js CHANGED
@@ -11,7 +11,7 @@ var endpointPrefix = '/api/rest/v1';
11
11
  var apiKey;
12
12
  var baseUrl = 'https://app.files.com';
13
13
  var sessionId = null;
14
- var version = '1.2.136';
14
+ var version = '1.2.138';
15
15
  var userAgent = "Files.com JavaScript SDK v".concat(version);
16
16
  var logLevel = _Logger.LogLevel.INFO;
17
17
  var debugRequest = false;
@@ -248,9 +248,9 @@ _Permission = Permission;
248
248
  return _Permission.list(params, options);
249
249
  });
250
250
  // Parameters:
251
+ // path (required) - string - Folder path
251
252
  // group_id - int64 - Group ID
252
- // path - string - Folder path
253
- // permission - string - Permission type. Can be `admin`, `full`, `readonly`, `writeonly`, `list`, or `history`
253
+ // permission - string - Permission type. Can be `admin`, `full`, `readonly`, `writeonly`, `list`, or `history`
254
254
  // recursive - boolean - Apply to subfolders recursively?
255
255
  // user_id - int64 - User ID. Provide `username` or `user_id`
256
256
  // username - string - User username. Provide `username` or `user_id`
@@ -264,11 +264,11 @@ _Permission = Permission;
264
264
  case 0:
265
265
  params = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
266
266
  options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
267
- if (!(params.group_id && !(0, _utils.isInt)(params.group_id))) {
267
+ if (params.path) {
268
268
  _context4.next = 4;
269
269
  break;
270
270
  }
271
- throw new errors.InvalidParameterError("Bad parameter: group_id must be of type Int, received ".concat((0, _utils.getType)(params.group_id)));
271
+ throw new errors.MissingParameterError('Parameter missing: path');
272
272
  case 4:
273
273
  if (!(params.path && !(0, _utils.isString)(params.path))) {
274
274
  _context4.next = 6;
@@ -276,30 +276,36 @@ _Permission = Permission;
276
276
  }
277
277
  throw new errors.InvalidParameterError("Bad parameter: path must be of type String, received ".concat((0, _utils.getType)(params.path)));
278
278
  case 6:
279
- if (!(params.permission && !(0, _utils.isString)(params.permission))) {
279
+ if (!(params.group_id && !(0, _utils.isInt)(params.group_id))) {
280
280
  _context4.next = 8;
281
281
  break;
282
282
  }
283
- throw new errors.InvalidParameterError("Bad parameter: permission must be of type String, received ".concat((0, _utils.getType)(params.permission)));
283
+ throw new errors.InvalidParameterError("Bad parameter: group_id must be of type Int, received ".concat((0, _utils.getType)(params.group_id)));
284
284
  case 8:
285
- if (!(params.user_id && !(0, _utils.isInt)(params.user_id))) {
285
+ if (!(params.permission && !(0, _utils.isString)(params.permission))) {
286
286
  _context4.next = 10;
287
287
  break;
288
288
  }
289
- throw new errors.InvalidParameterError("Bad parameter: user_id must be of type Int, received ".concat((0, _utils.getType)(params.user_id)));
289
+ throw new errors.InvalidParameterError("Bad parameter: permission must be of type String, received ".concat((0, _utils.getType)(params.permission)));
290
290
  case 10:
291
- if (!(params.username && !(0, _utils.isString)(params.username))) {
291
+ if (!(params.user_id && !(0, _utils.isInt)(params.user_id))) {
292
292
  _context4.next = 12;
293
293
  break;
294
294
  }
295
- throw new errors.InvalidParameterError("Bad parameter: username must be of type String, received ".concat((0, _utils.getType)(params.username)));
295
+ throw new errors.InvalidParameterError("Bad parameter: user_id must be of type Int, received ".concat((0, _utils.getType)(params.user_id)));
296
296
  case 12:
297
- _context4.next = 14;
298
- return _Api.default.sendRequest('/permissions', 'POST', params, options);
297
+ if (!(params.username && !(0, _utils.isString)(params.username))) {
298
+ _context4.next = 14;
299
+ break;
300
+ }
301
+ throw new errors.InvalidParameterError("Bad parameter: username must be of type String, received ".concat((0, _utils.getType)(params.username)));
299
302
  case 14:
303
+ _context4.next = 16;
304
+ return _Api.default.sendRequest('/permissions', 'POST', params, options);
305
+ case 16:
300
306
  response = _context4.sent;
301
307
  return _context4.abrupt("return", new _Permission(response === null || response === void 0 ? void 0 : response.data, options));
302
- case 16:
308
+ case 18:
303
309
  case "end":
304
310
  return _context4.stop();
305
311
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "files.com",
3
- "version": "1.2.136",
3
+ "version": "1.2.138",
4
4
  "description": "Files.com SDK for JavaScript",
5
5
  "keywords": [
6
6
  "files.com",
package/src/Files.js CHANGED
@@ -5,7 +5,7 @@ const endpointPrefix = '/api/rest/v1'
5
5
  let apiKey
6
6
  let baseUrl = 'https://app.files.com'
7
7
  let sessionId = null
8
- const version = '1.2.136'
8
+ const version = '1.2.138'
9
9
  let userAgent = `Files.com JavaScript SDK v${version}`
10
10
 
11
11
  let logLevel = LogLevel.INFO
@@ -162,21 +162,25 @@ class Permission {
162
162
  Permission.list(params, options)
163
163
 
164
164
  // Parameters:
165
+ // path (required) - string - Folder path
165
166
  // group_id - int64 - Group ID
166
- // path - string - Folder path
167
- // permission - string - Permission type. Can be `admin`, `full`, `readonly`, `writeonly`, `list`, or `history`
167
+ // permission - string - Permission type. Can be `admin`, `full`, `readonly`, `writeonly`, `list`, or `history`
168
168
  // recursive - boolean - Apply to subfolders recursively?
169
169
  // user_id - int64 - User ID. Provide `username` or `user_id`
170
170
  // username - string - User username. Provide `username` or `user_id`
171
171
  static create = async (params = {}, options = {}) => {
172
- if (params.group_id && !isInt(params.group_id)) {
173
- throw new errors.InvalidParameterError(`Bad parameter: group_id must be of type Int, received ${getType(params.group_id)}`)
172
+ if (!params.path) {
173
+ throw new errors.MissingParameterError('Parameter missing: path')
174
174
  }
175
175
 
176
176
  if (params.path && !isString(params.path)) {
177
177
  throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
178
178
  }
179
179
 
180
+ if (params.group_id && !isInt(params.group_id)) {
181
+ throw new errors.InvalidParameterError(`Bad parameter: group_id must be of type Int, received ${getType(params.group_id)}`)
182
+ }
183
+
180
184
  if (params.permission && !isString(params.permission)) {
181
185
  throw new errors.InvalidParameterError(`Bad parameter: permission must be of type String, received ${getType(params.permission)}`)
182
186
  }