files.com 1.2.137 → 1.2.138
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 +109 -110
- 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
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
213
|
+
```javascript title="Sort Example"
|
|
214
|
+
Files.setApiKey('my-key');
|
|
224
215
|
|
|
225
|
-
|
|
216
|
+
// Users, sorted by username in ascending order.
|
|
217
|
+
const users = await User.list({
|
|
218
|
+
sort_by: { username: "asc"}
|
|
219
|
+
});
|
|
226
220
|
|
|
227
|
-
|
|
221
|
+
users.forEach(user => {
|
|
222
|
+
console.log(user.username);
|
|
223
|
+
});
|
|
224
|
+
```
|
|
228
225
|
|
|
229
|
-
|
|
226
|
+
### Filtering
|
|
230
227
|
|
|
231
|
-
|
|
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
|
-
|
|
232
|
+
Each resource supports a unique set of valid filter fields, filter combinations, and combinations of
|
|
233
|
+
filters and sort fields.
|
|
234
234
|
|
|
235
|
-
|
|
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
|
-
|
|
238
|
+
#### Filter Types
|
|
238
239
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
260
|
-
|
|
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
|
-
|
|
273
|
-
|
|
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
|
-
|
|
286
|
-
|
|
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="
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
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.
|
|
1
|
+
1.2.138
|
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.138';
|
|
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