files.com 1.2.197 → 1.2.199
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.
- package/README.md +183 -66
- package/_VERSION +1 -1
- package/lib/Files.js +1 -1
- package/package.json +1 -1
- package/src/Files.js +1 -1
package/README.md
CHANGED
|
@@ -79,13 +79,27 @@ access to the entire API. If the user is not an administrator, you will only be
|
|
|
79
79
|
that user can access, and no access will be granted to site administration functions in the API.
|
|
80
80
|
|
|
81
81
|
```javascript title="Example Request"
|
|
82
|
+
import Files from 'files.com/lib/Files';
|
|
83
|
+
import User from 'files.com/lib/models/User';
|
|
84
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
85
|
+
|
|
82
86
|
Files.setApiKey('YOUR_API_KEY');
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
try {
|
|
89
|
+
// Alternatively, you can specify the API key on a per-object basis in the second parameter to a model constructor.
|
|
90
|
+
const user = new User(params, { apiKey: 'YOUR_API_KEY' });
|
|
86
91
|
|
|
87
|
-
// You may also specify the API key on a per-request basis in the final parameter to static methods.
|
|
88
|
-
await User.find(id, params, { apiKey: 'YOUR_API_KEY' });
|
|
92
|
+
// You may also specify the API key on a per-request basis in the final parameter to static methods.
|
|
93
|
+
await User.find(id, params, { apiKey: 'YOUR_API_KEY' });
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
96
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
97
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
98
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
99
|
+
} else {
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
89
103
|
```
|
|
90
104
|
|
|
91
105
|
Don't forget to replace the placeholder, `YOUR_API_KEY`, with your actual API key.
|
|
@@ -110,7 +124,20 @@ password.
|
|
|
110
124
|
This returns a session object that can be used to authenticate SDK method calls.
|
|
111
125
|
|
|
112
126
|
```javascript title="Example Request"
|
|
113
|
-
|
|
127
|
+
import Session from 'files.com/lib/models/Session';
|
|
128
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const session = await Session.create({ username: 'motor', password: 'vroom' });
|
|
132
|
+
} catch (err) {
|
|
133
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
134
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
135
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
136
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
137
|
+
} else {
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
114
141
|
```
|
|
115
142
|
|
|
116
143
|
#### Using a Session
|
|
@@ -118,14 +145,28 @@ const session = await Session.create({ username: 'motor', password: 'vroom' });
|
|
|
118
145
|
Once a session has been created, you can store the session globally, use the session per object, or use the session per request to authenticate SDK operations.
|
|
119
146
|
|
|
120
147
|
```javascript title="Example Request"
|
|
148
|
+
import Files from 'files.com/lib/Files';
|
|
149
|
+
import User from 'files.com/lib/models/User';
|
|
150
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
151
|
+
|
|
121
152
|
// You may set the returned session ID to be used by default for subsequent requests.
|
|
122
153
|
Files.setSessionId(session.id);
|
|
123
154
|
|
|
124
|
-
|
|
125
|
-
|
|
155
|
+
try {
|
|
156
|
+
// Alternatively, you can specify the session ID on a per-object basis in the second parameter to a model constructor.
|
|
157
|
+
const user = new User(params, { session_id: session.id });
|
|
126
158
|
|
|
127
|
-
// You may also specify the session ID on a per-request basis in the final parameter to static methods.
|
|
128
|
-
await User.find(id, params, { session_id: session.id });
|
|
159
|
+
// You may also specify the session ID on a per-request basis in the final parameter to static methods.
|
|
160
|
+
await User.find(id, params, { session_id: session.id });
|
|
161
|
+
} catch (err) {
|
|
162
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
163
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
164
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
165
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
166
|
+
} else {
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
129
170
|
```
|
|
130
171
|
|
|
131
172
|
#### Logging Out
|
|
@@ -133,7 +174,20 @@ await User.find(id, params, { session_id: session.id });
|
|
|
133
174
|
User sessions can be ended calling the `destroy` method on the `session` object.
|
|
134
175
|
|
|
135
176
|
```javascript title="Example Request"
|
|
136
|
-
|
|
177
|
+
import Session from 'files.com/lib/models/Session';
|
|
178
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
await Session.destroy();
|
|
182
|
+
} catch (err) {
|
|
183
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
184
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
185
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
186
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
187
|
+
} else {
|
|
188
|
+
throw err;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
137
191
|
```
|
|
138
192
|
|
|
139
193
|
## Configuration
|
|
@@ -148,6 +202,8 @@ Setting the base URL for the API is required if your site is configured to disab
|
|
|
148
202
|
This can also be set to use a mock server in development or CI.
|
|
149
203
|
|
|
150
204
|
```javascript title="Example setting"
|
|
205
|
+
import Files from 'files.com/lib/Files';
|
|
206
|
+
|
|
151
207
|
Files.setBaseUrl("https://MY-SUBDOMAIN.files.com");
|
|
152
208
|
```
|
|
153
209
|
|
|
@@ -162,7 +218,8 @@ Supported values:
|
|
|
162
218
|
* LogLevel.DEBUG
|
|
163
219
|
|
|
164
220
|
```javascript title="Example setting"
|
|
165
|
-
import
|
|
221
|
+
import Files from 'files.com/lib/Files';
|
|
222
|
+
import { LogLevel } from 'files.com/lib/Logger';
|
|
166
223
|
|
|
167
224
|
Files.setLogLevel(LogLevel.INFO);
|
|
168
225
|
```
|
|
@@ -172,6 +229,8 @@ Files.setLogLevel(LogLevel.INFO);
|
|
|
172
229
|
Enable debug logging of API requests and/or response headers. Both settings default to `false`.
|
|
173
230
|
|
|
174
231
|
```javascript title="Example setting"
|
|
232
|
+
import Files from 'files.com/lib/Files';
|
|
233
|
+
|
|
175
234
|
Files.configureDebugging({
|
|
176
235
|
debugRequest: true,
|
|
177
236
|
debugResponseHeaders: true,
|
|
@@ -181,6 +240,8 @@ Files.configureDebugging({
|
|
|
181
240
|
#### Network Settings
|
|
182
241
|
|
|
183
242
|
```javascript title="Example setting"
|
|
243
|
+
import Files from 'files.com/lib/Files';
|
|
244
|
+
|
|
184
245
|
Files.configureNetwork({
|
|
185
246
|
// max retries (default: 3)
|
|
186
247
|
maxNetworkRetries: 3,
|
|
@@ -215,16 +276,27 @@ The argument value is a Javascript object that has a property of the resource fi
|
|
|
215
276
|
a value of either ```"asc"``` or ```"desc"``` to specify the sort order.
|
|
216
277
|
|
|
217
278
|
```javascript title="Sort Example"
|
|
218
|
-
|
|
279
|
+
import User from 'files.com/lib/models/User';
|
|
280
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
219
281
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
282
|
+
try {
|
|
283
|
+
// Users, sorted by username in ascending order.
|
|
284
|
+
const users = await User.list({
|
|
285
|
+
sort_by: { username: "asc" }
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
users.forEach(user => {
|
|
289
|
+
console.log(user.username);
|
|
290
|
+
});
|
|
291
|
+
} catch (err) {
|
|
292
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
293
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
294
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
295
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
296
|
+
} else {
|
|
297
|
+
throw err;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
228
300
|
```
|
|
229
301
|
|
|
230
302
|
### Filtering
|
|
@@ -251,57 +323,102 @@ to filter on and a passed in value to use in the filter comparison.
|
|
|
251
323
|
| `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). |
|
|
252
324
|
|
|
253
325
|
```javascript title="Exact Filter Example"
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
// Users who are not site admins.
|
|
257
|
-
const users = await User.list({
|
|
258
|
-
filter: { not_site_admin: true }
|
|
259
|
-
});
|
|
326
|
+
import User from 'files.com/lib/models/User';
|
|
327
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
260
328
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
329
|
+
try {
|
|
330
|
+
// Users who are not site admins.
|
|
331
|
+
const users = await User.list({
|
|
332
|
+
filter: { not_site_admin: true }
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
users.forEach(user => {
|
|
336
|
+
console.log(user.username);
|
|
337
|
+
});
|
|
338
|
+
} catch (err) {
|
|
339
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
340
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
341
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
342
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
343
|
+
} else {
|
|
344
|
+
throw err;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
264
347
|
```
|
|
265
348
|
|
|
266
349
|
```javascript title="Range Filter Example"
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// Users who haven't logged in since 2024-01-01.
|
|
270
|
-
const users = await User.list({
|
|
271
|
-
filter_gteq: { last_login_at: "2024-01-01" }
|
|
272
|
-
});
|
|
350
|
+
import User from 'files.com/lib/models/User';
|
|
351
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
273
352
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
353
|
+
try {
|
|
354
|
+
// Users who haven't logged in since 2024-01-01.
|
|
355
|
+
const users = await User.list({
|
|
356
|
+
filter_gteq: { last_login_at: "2024-01-01" }
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
users.forEach(user => {
|
|
360
|
+
console.log(user.username);
|
|
361
|
+
});
|
|
362
|
+
} catch (err) {
|
|
363
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
364
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
365
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
366
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
367
|
+
} else {
|
|
368
|
+
throw err;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
```
|
|
277
372
|
```
|
|
278
373
|
|
|
279
374
|
```javascript title="Pattern Filter Example"
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
// Users whose usernames start with 'test'.
|
|
283
|
-
const users = await User.list({
|
|
284
|
-
filter_prefix: { username: "test" }
|
|
285
|
-
});
|
|
375
|
+
import User from 'files.com/lib/models/User';
|
|
376
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
286
377
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
378
|
+
try {
|
|
379
|
+
// Users whose usernames start with 'test'.
|
|
380
|
+
const users = await User.list({
|
|
381
|
+
filter_prefix: { username: "test" }
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
users.forEach(user => {
|
|
385
|
+
console.log(user.username);
|
|
386
|
+
});
|
|
387
|
+
} catch (err) {
|
|
388
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
389
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
390
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
391
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
392
|
+
} else {
|
|
393
|
+
throw err;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
290
396
|
```
|
|
291
397
|
|
|
292
398
|
```javascript title="Combination Filter with Sort Example"
|
|
293
|
-
|
|
399
|
+
import User from 'files.com/lib/models/User';
|
|
400
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
294
401
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
402
|
+
try {
|
|
403
|
+
// Users whose usernames start with 'test' and are not site admins, sorted by last login date.
|
|
404
|
+
const users = await User.list({
|
|
405
|
+
filter_prefix: { username: "test" },
|
|
406
|
+
filter: { not_site_admin: true },
|
|
407
|
+
sort_by: { last_login_at: "asc" }
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
users.forEach(user => {
|
|
411
|
+
console.log(user.username);
|
|
412
|
+
});
|
|
413
|
+
} catch (err) {
|
|
414
|
+
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
415
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
416
|
+
} else if (err instanceof FilesErrors.FilesError) {
|
|
417
|
+
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
418
|
+
} else {
|
|
419
|
+
throw err;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
305
422
|
```
|
|
306
423
|
|
|
307
424
|
## Errors
|
|
@@ -322,14 +439,14 @@ Use standard Javascript exception handling to detect and deal with errors. It i
|
|
|
322
439
|
catch the general `FilesError` exception as a catch-all.
|
|
323
440
|
|
|
324
441
|
```javascript title="Example Error Handling"
|
|
325
|
-
import Session from 'files.com/lib/models/Session
|
|
326
|
-
import * as FilesErrors from 'files.com/lib/Errors
|
|
442
|
+
import Session from 'files.com/lib/models/Session';
|
|
443
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
327
444
|
|
|
328
445
|
try {
|
|
329
446
|
const session = await Session.create({ username: 'USERNAME', password: 'BADPASSWORD' });
|
|
330
|
-
} catch(err) {
|
|
447
|
+
} catch (err) {
|
|
331
448
|
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
332
|
-
console.error(`
|
|
449
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
333
450
|
} else if (err instanceof FilesErrors.FilesError) {
|
|
334
451
|
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
335
452
|
} else {
|
|
@@ -346,7 +463,7 @@ SDK errors are general errors that occur within the SDK code. These errors gene
|
|
|
346
463
|
exception classes inherit from a standard `FilesError` base class.
|
|
347
464
|
|
|
348
465
|
```javascript title="Example SDK Exception Class Inheritance Structure"
|
|
349
|
-
import * as FilesErrors from 'files.com/lib/Errors
|
|
466
|
+
import * as FilesErrors from 'files.com/lib/Errors'
|
|
350
467
|
|
|
351
468
|
FilesErrors.ConfigurationError ->
|
|
352
469
|
FilesErrors.FilesError ->
|
|
@@ -367,8 +484,8 @@ Error
|
|
|
367
484
|
API errors are errors returned by the Files.com API. Each exception class inherits from an error group base class.
|
|
368
485
|
The error group base class indicates a particular type of error.
|
|
369
486
|
|
|
370
|
-
```
|
|
371
|
-
import * as FilesErrors from 'files.com/lib/Errors
|
|
487
|
+
```javascript title="Example API Exception Class Inheritance Structure"
|
|
488
|
+
import * as FilesErrors from 'files.com/lib/Errors'
|
|
372
489
|
|
|
373
490
|
FilesErrors.NotAuthorized_FolderAdminPermissionRequiredError ->
|
|
374
491
|
FilesErrors.NotAuthorizedError ->
|
|
@@ -562,7 +679,7 @@ when handling errors related to duplicate file names and when developing tools f
|
|
|
562
679
|
synchronization.
|
|
563
680
|
|
|
564
681
|
```javascript title="Compare Case-Insensitive Files and Paths"
|
|
565
|
-
import { pathNormalizer } from 'files.com/lib/utils
|
|
682
|
+
import { pathNormalizer } from 'files.com/lib/utils';
|
|
566
683
|
|
|
567
684
|
if (pathNormalizer.same('Fïłèńämê.Txt', 'filename.txt')) {
|
|
568
685
|
// the paths are the same
|
package/_VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.2.
|
|
1
|
+
1.2.199
|
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.
|
|
14
|
+
var version = '1.2.199';
|
|
15
15
|
var userAgent = "Files.com JavaScript SDK v".concat(version);
|
|
16
16
|
var logLevel = _Logger.LogLevel.INFO;
|
|
17
17
|
var debugRequest = false;
|
package/package.json
CHANGED
package/src/Files.js
CHANGED