files.com 1.2.198 → 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 +154 -54
- 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
|
@@ -81,14 +81,25 @@ that user can access, and no access will be granted to site administration funct
|
|
|
81
81
|
```javascript title="Example Request"
|
|
82
82
|
import Files from 'files.com/lib/Files';
|
|
83
83
|
import User from 'files.com/lib/models/User';
|
|
84
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
84
85
|
|
|
85
86
|
Files.setApiKey('YOUR_API_KEY');
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
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' });
|
|
89
91
|
|
|
90
|
-
// You may also specify the API key on a per-request basis in the final parameter to static methods.
|
|
91
|
-
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
|
+
}
|
|
92
103
|
```
|
|
93
104
|
|
|
94
105
|
Don't forget to replace the placeholder, `YOUR_API_KEY`, with your actual API key.
|
|
@@ -114,8 +125,19 @@ This returns a session object that can be used to authenticate SDK method calls.
|
|
|
114
125
|
|
|
115
126
|
```javascript title="Example Request"
|
|
116
127
|
import Session from 'files.com/lib/models/Session';
|
|
128
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
117
129
|
|
|
118
|
-
|
|
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
|
+
}
|
|
119
141
|
```
|
|
120
142
|
|
|
121
143
|
#### Using a Session
|
|
@@ -125,15 +147,26 @@ Once a session has been created, you can store the session globally, use the ses
|
|
|
125
147
|
```javascript title="Example Request"
|
|
126
148
|
import Files from 'files.com/lib/Files';
|
|
127
149
|
import User from 'files.com/lib/models/User';
|
|
150
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
128
151
|
|
|
129
152
|
// You may set the returned session ID to be used by default for subsequent requests.
|
|
130
153
|
Files.setSessionId(session.id);
|
|
131
154
|
|
|
132
|
-
|
|
133
|
-
|
|
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 });
|
|
134
158
|
|
|
135
|
-
// You may also specify the session ID on a per-request basis in the final parameter to static methods.
|
|
136
|
-
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
|
+
}
|
|
137
170
|
```
|
|
138
171
|
|
|
139
172
|
#### Logging Out
|
|
@@ -142,8 +175,19 @@ User sessions can be ended calling the `destroy` method on the `session` object.
|
|
|
142
175
|
|
|
143
176
|
```javascript title="Example Request"
|
|
144
177
|
import Session from 'files.com/lib/models/Session';
|
|
178
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
145
179
|
|
|
146
|
-
|
|
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
|
+
}
|
|
147
191
|
```
|
|
148
192
|
|
|
149
193
|
## Configuration
|
|
@@ -233,15 +277,26 @@ a value of either ```"asc"``` or ```"desc"``` to specify the sort order.
|
|
|
233
277
|
|
|
234
278
|
```javascript title="Sort Example"
|
|
235
279
|
import User from 'files.com/lib/models/User';
|
|
280
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
236
281
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
+
}
|
|
245
300
|
```
|
|
246
301
|
|
|
247
302
|
### Filtering
|
|
@@ -269,56 +324,101 @@ to filter on and a passed in value to use in the filter comparison.
|
|
|
269
324
|
|
|
270
325
|
```javascript title="Exact Filter Example"
|
|
271
326
|
import User from 'files.com/lib/models/User';
|
|
327
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
272
328
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
+
}
|
|
281
347
|
```
|
|
282
348
|
|
|
283
349
|
```javascript title="Range Filter Example"
|
|
284
350
|
import User from 'files.com/lib/models/User';
|
|
351
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
285
352
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
+
```
|
|
294
372
|
```
|
|
295
373
|
|
|
296
374
|
```javascript title="Pattern Filter Example"
|
|
297
375
|
import User from 'files.com/lib/models/User';
|
|
376
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
298
377
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
+
}
|
|
307
396
|
```
|
|
308
397
|
|
|
309
398
|
```javascript title="Combination Filter with Sort Example"
|
|
310
399
|
import User from 'files.com/lib/models/User';
|
|
400
|
+
import * as FilesErrors from 'files.com/lib/Errors';
|
|
311
401
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
+
}
|
|
322
422
|
```
|
|
323
423
|
|
|
324
424
|
## Errors
|
|
@@ -344,9 +444,9 @@ import * as FilesErrors from 'files.com/lib/Errors';
|
|
|
344
444
|
|
|
345
445
|
try {
|
|
346
446
|
const session = await Session.create({ username: 'USERNAME', password: 'BADPASSWORD' });
|
|
347
|
-
} catch(err) {
|
|
447
|
+
} catch (err) {
|
|
348
448
|
if (err instanceof FilesErrors.NotAuthenticatedError) {
|
|
349
|
-
console.error(`
|
|
449
|
+
console.error(`Authentication Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
350
450
|
} else if (err instanceof FilesErrors.FilesError) {
|
|
351
451
|
console.error(`Unknown Error Occurred (${err.constructor.name}): ${err.error}`);
|
|
352
452
|
} else {
|
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