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 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
- // Alternatively, you can specify the API key on a per-object basis in the second parameter to a model constructor.
88
- const user = new User(params, { apiKey: 'YOUR_API_KEY' });
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
- const session = await Session.create({ username: 'motor', password: 'vroom' });
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
- // Alternatively, you can specify the session ID on a per-object basis in the second parameter to a model constructor.
133
- const user = new User(params, { session_id: session.id });
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
- await Session.destroy();
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
- // Users, sorted by username in ascending order.
238
- const users = await User.list({
239
- sort_by: { username: "asc"}
240
- });
241
-
242
- users.forEach(user => {
243
- console.log(user.username);
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
- // Users who are not site admins.
274
- const users = await User.list({
275
- filter: { not_site_admin: true }
276
- });
277
-
278
- users.forEach(user => {
279
- console.log(user.username);
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
- // Users who haven't logged in since 2024-01-01.
287
- const users = await User.list({
288
- filter_gteq: { last_login_at: "2024-01-01" }
289
- });
290
-
291
- users.forEach(user => {
292
- console.log(user.username);
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
- // Users whose usernames start with 'test'.
300
- const users = await User.list({
301
- filter_prefix: { username: "test" }
302
- });
303
-
304
- users.forEach(user => {
305
- console.log(user.username);
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
- // Users whose usernames start with 'test' and are not site admins, sorted by last login date.
313
- const users = await User.list({
314
- filter_prefix: { username: "test" },
315
- filter: { not_site_admin: true },
316
- sort_by: { last_login_at: "asc" }
317
- });
318
-
319
- users.forEach(user => {
320
- console.log(user.username);
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(`Authorization Error Occurred (${err.constructor.name}): ${err.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.198
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.198';
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "files.com",
3
- "version": "1.2.198",
3
+ "version": "1.2.199",
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.198'
8
+ const version = '1.2.199'
9
9
  let userAgent = `Files.com JavaScript SDK v${version}`
10
10
 
11
11
  let logLevel = LogLevel.INFO