files.com 1.2.234 → 1.2.236

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
@@ -420,6 +420,22 @@ try {
420
420
  }
421
421
  ```
422
422
 
423
+ ## Foreign Language Support
424
+
425
+ The Files.com Javascript SDK supports localized responses by using the `Files.setLanguage()` configuration method.
426
+ When configured, this guides the API in selecting a preferred language for applicable response content.
427
+
428
+ Language support currently applies to select human-facing fields only, such as notification messages
429
+ and error descriptions.
430
+
431
+ If the specified language is not supported or the value is omitted, the API defaults to English.
432
+
433
+ ```javascript title="Example Request"
434
+ import Files from 'files.com/lib/Files';
435
+
436
+ Files.setLanguage('es');
437
+ ```
438
+
423
439
  ## Errors
424
440
 
425
441
  The Files.com JavaScript SDK will return errors by raising exceptions. There are many exception classes defined in the Files SDK that correspond
package/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.234
1
+ 1.2.236
@@ -31,6 +31,7 @@
31
31
  "provision_group_inclusion": "Employees",
32
32
  "provision_group_required": "example",
33
33
  "provision_email_signup_groups": "Employees",
34
+ "provision_readonly_site_admin_groups": "Employees",
34
35
  "provision_site_admin_groups": "Employees",
35
36
  "provision_group_admin_groups": "Employees",
36
37
  "provision_attachments_permission": true,
@@ -81,6 +82,7 @@
81
82
  * `provision_group_inclusion` (string): Comma-separated list of group names for groups (with optional wildcards) that will be auto-provisioned.
82
83
  * `provision_group_required` (string): Comma or newline separated list of group names (with optional wildcards) to require membership for user provisioning.
83
84
  * `provision_email_signup_groups` (string): Comma-separated list of group names whose members will be created with email_signup authentication.
85
+ * `provision_readonly_site_admin_groups` (string): Comma-separated list of group names whose members will be created as Read-Only Site Admins.
84
86
  * `provision_site_admin_groups` (string): Comma-separated list of group names whose members will be created as Site Admins.
85
87
  * `provision_group_admin_groups` (string): Comma-separated list of group names whose members will be provisioned as Group Admins.
86
88
  * `provision_attachments_permission` (boolean):
package/lib/Api.js CHANGED
@@ -266,6 +266,7 @@ _Api = Api;
266
266
  var params,
267
267
  options,
268
268
  metadata,
269
+ languageHeader,
269
270
  headers,
270
271
  isExternal,
271
272
  sessionId,
@@ -294,39 +295,42 @@ _Api = Api;
294
295
  params = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : null;
295
296
  options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
296
297
  metadata = _args4.length > 4 && _args4[4] !== undefined ? _args4[4] : null;
297
- headers = _objectSpread(_objectSpread({
298
+ languageHeader = _Files.default.getLanguage() ? {
299
+ 'Accept-Language': _Files.default.getLanguage()
300
+ } : {};
301
+ headers = _objectSpread(_objectSpread(_objectSpread({
298
302
  Accept: 'application/json'
299
- }, options.headers), {}, {
303
+ }, languageHeader), options.headers), {}, {
300
304
  'User-Agent': _Files.default.getUserAgent()
301
305
  });
302
306
  isExternal = /^[a-zA-Z]+:\/\//.test(path);
303
307
  if (isExternal) {
304
- _context4.next = 17;
308
+ _context4.next = 18;
305
309
  break;
306
310
  }
307
311
  sessionId = options.sessionId || _Files.default.getSessionId();
308
312
  if (!sessionId) {
309
- _context4.next = 11;
313
+ _context4.next = 12;
310
314
  break;
311
315
  }
312
316
  headers['X-FilesAPI-Auth'] = sessionId;
313
- _context4.next = 17;
317
+ _context4.next = 18;
314
318
  break;
315
- case 11:
319
+ case 12:
316
320
  isCreatingSession = path === '/sessions' && verb.toUpperCase() === 'POST'; // api key cannot be used when creating a session
317
321
  if (isCreatingSession) {
318
- _context4.next = 17;
322
+ _context4.next = 18;
319
323
  break;
320
324
  }
321
325
  apiKey = options.apiKey || _Files.default.getApiKey();
322
326
  if (apiKey) {
323
- _context4.next = 16;
327
+ _context4.next = 17;
324
328
  break;
325
329
  }
326
330
  throw new errors.ConfigurationError('API key has not been set - use Files.setApiKey() to set it');
327
- case 16:
328
- headers['X-FilesAPI-Key'] = apiKey;
329
331
  case 17:
332
+ headers['X-FilesAPI-Key'] = apiKey;
333
+ case 18:
330
334
  updatedOptions = _objectSpread(_objectSpread({}, options), {}, {
331
335
  headers: headers
332
336
  });
@@ -368,12 +372,12 @@ _Api = Api;
368
372
  })
369
373
  }));
370
374
  }
371
- _context4.next = 24;
375
+ _context4.next = 25;
372
376
  return _Api._sendVerbatim(requestPath, verb, updatedOptions);
373
- case 24:
377
+ case 25:
374
378
  response = _context4.sent;
375
379
  return _context4.abrupt("return", _Api._autoPaginate(path, verb, params, updatedOptions, response, metadata));
376
- case 26:
380
+ case 27:
377
381
  case "end":
378
382
  return _context4.stop();
379
383
  }
package/lib/Files.js CHANGED
@@ -11,7 +11,8 @@ 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.234';
14
+ var language = null;
15
+ var version = '1.2.236';
15
16
  var userAgent = "Files.com JavaScript SDK v".concat(version);
16
17
  var logLevel = _Logger.LogLevel.INFO;
17
18
  var debugRequest = false;
@@ -48,6 +49,12 @@ var Files = /*#__PURE__*/(0, _createClass2.default)(function Files() {
48
49
  (0, _defineProperty2.default)(Files, "getSessionId", function () {
49
50
  return sessionId;
50
51
  });
52
+ (0, _defineProperty2.default)(Files, "getLanguage", function () {
53
+ return language;
54
+ });
55
+ (0, _defineProperty2.default)(Files, "setLanguage", function (value) {
56
+ language = value;
57
+ });
51
58
  (0, _defineProperty2.default)(Files, "getEndpointPrefix", function () {
52
59
  return endpointPrefix;
53
60
  });
@@ -141,6 +141,10 @@ var SsoStrategy = /*#__PURE__*/(0, _createClass2.default)(function SsoStrategy()
141
141
  (0, _defineProperty2.default)(this, "getProvisionEmailSignupGroups", function () {
142
142
  return _this.attributes.provision_email_signup_groups;
143
143
  });
144
+ // string # Comma-separated list of group names whose members will be created as Read-Only Site Admins.
145
+ (0, _defineProperty2.default)(this, "getProvisionReadonlySiteAdminGroups", function () {
146
+ return _this.attributes.provision_readonly_site_admin_groups;
147
+ });
144
148
  // string # Comma-separated list of group names whose members will be created as Site Admins.
145
149
  (0, _defineProperty2.default)(this, "getProvisionSiteAdminGroups", function () {
146
150
  return _this.attributes.provision_site_admin_groups;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "files.com",
3
- "version": "1.2.234",
3
+ "version": "1.2.236",
4
4
  "description": "Files.com SDK for JavaScript",
5
5
  "keywords": [
6
6
  "files.com",
package/src/Api.js CHANGED
@@ -172,8 +172,11 @@ class Api {
172
172
  }
173
173
 
174
174
  static sendRequest = async (path, verb, params = null, options = {}, metadata = null) => {
175
+ const languageHeader = Files.getLanguage() ? { 'Accept-Language': Files.getLanguage() } : {}
176
+
175
177
  const headers = {
176
178
  Accept: 'application/json',
179
+ ...languageHeader,
177
180
  ...options.headers,
178
181
  'User-Agent': Files.getUserAgent(),
179
182
  }
package/src/Files.js CHANGED
@@ -5,7 +5,8 @@ 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.234'
8
+ let language = null
9
+ const version = '1.2.236'
9
10
  let userAgent = `Files.com JavaScript SDK v${version}`
10
11
 
11
12
  let logLevel = LogLevel.INFO
@@ -35,6 +36,10 @@ class Files {
35
36
 
36
37
  static getSessionId = () => sessionId
37
38
 
39
+ static getLanguage = () => language
40
+
41
+ static setLanguage = value => { language = value }
42
+
38
43
  static getEndpointPrefix = () => endpointPrefix
39
44
 
40
45
  static setLogLevel = value => { logLevel = value }
@@ -109,6 +109,9 @@ class SsoStrategy {
109
109
  // string # Comma-separated list of group names whose members will be created with email_signup authentication.
110
110
  getProvisionEmailSignupGroups = () => this.attributes.provision_email_signup_groups
111
111
 
112
+ // string # Comma-separated list of group names whose members will be created as Read-Only Site Admins.
113
+ getProvisionReadonlySiteAdminGroups = () => this.attributes.provision_readonly_site_admin_groups
114
+
112
115
  // string # Comma-separated list of group names whose members will be created as Site Admins.
113
116
  getProvisionSiteAdminGroups = () => this.attributes.provision_site_admin_groups
114
117
 
@@ -1,3 +1,39 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // To run this test suite, first set environment variables:
3
+ //
4
+ // required:
5
+ // FILES_API_KEY - set to your API key
6
+ // FILES_API_DOMAIN - set to your Files.com subdomain (e.g. mysite.files.com)
7
+ //
8
+ // required only if testSession() is run, otherwise can be omitted:
9
+ // FILES_SESSION_USERNAME - username to login with
10
+ // FILES_SESSION_PASSWORD - password to login with
11
+ //
12
+ // optional:
13
+ // USER_COUNT_TO_TRIGGER_PAGINATION - defaults to 1, set to a number that will
14
+ // require multiple page requests to fetch all users, but don't set it too low;
15
+ // if you have many users, then "1" will trigger a fetch for every single user
16
+ //
17
+ ///////////////////////////////////////////////////////////////////////////////
18
+ //
19
+ // Next, in the ../../../ directory, build the SDK:
20
+ //
21
+ // npm install
22
+ // npm run build
23
+ //
24
+ // Then, in the ../ directory, build the test suite:
25
+ //
26
+ // npm install
27
+ // npm run build
28
+ //
29
+ // Finally, execute the current file:
30
+ //
31
+ // npm run test
32
+ //
33
+ ///////////////////////////////////////////////////////////////////////////////
34
+ // Note: you can comment out at the bottom of this file any tests you don't want to run.
35
+ ///////////////////////////////////////////////////////////////////////////////
36
+
1
37
  import Files from 'files.com/lib/Files'
2
38
  import Logger, { LogLevel } from 'files.com/lib/Logger'
3
39
  import ApiKey from 'files.com/lib/models/ApiKey'
@@ -27,13 +63,15 @@ if (!apiDomain) {
27
63
  Files.setApiKey(apiKey)
28
64
  Files.setBaseUrl(`https://${apiDomain}`)
29
65
 
30
- // temp for testing against staging
31
66
  if (apiDomain.substr(-10) === 'staging.av') {
32
67
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
33
68
  }
34
69
 
35
70
  const DEBUG_MODE = false
36
71
 
72
+ // any user count that will require multiple page requests to fetch all users
73
+ const USER_COUNT_TO_TRIGGER_PAGINATION = process.env.USER_COUNT_TO_TRIGGER_PAGINATION || 1
74
+
37
75
  Files.setLogLevel(DEBUG_MODE ? LogLevel.DEBUG : LogLevel.INFO)
38
76
 
39
77
  Files.configureDebugging({
@@ -53,7 +91,7 @@ const testSuite = async () => {
53
91
  autoPaginate: false,
54
92
  })
55
93
 
56
- const firstPageItems = await Folder.listFor('/', { per_page: 1 })
94
+ const firstPageItems = await Folder.listFor('/', { per_page: USER_COUNT_TO_TRIGGER_PAGINATION })
57
95
 
58
96
  invariant(firstPageItems.length === 1, 'First page should have 1 item')
59
97
 
@@ -260,6 +298,41 @@ const testSuite = async () => {
260
298
  Logger.info('***** testUserListAndUpdate() succeeded! *****');
261
299
  }
262
300
 
301
+ const testLanguage = async () => {
302
+ Files.setLanguage('es');
303
+ invariant(Files.getLanguage() === 'es');
304
+
305
+ const savedLogLevel = Files.getLogLevel()
306
+ const savedDebugRequest = Files.shouldDebugRequest()
307
+ const savedDebugResponseHeaders = Files.shouldDebugResponseHeaders()
308
+ Files.setLogLevel(LogLevel.DEBUG)
309
+ Files.configureDebugging({
310
+ debugRequest: true,
311
+ debugResponseHeaders: true,
312
+ })
313
+
314
+ const logs = []
315
+ const savedConsoleLog = console.log
316
+ console.log = (...args) => {
317
+ logs.push(args.map(JSON.stringify).join(' '))
318
+ }
319
+
320
+ await ApiKey.list({ user_id: 0 })
321
+
322
+ console.log = savedConsoleLog
323
+
324
+ Files.setLogLevel(savedLogLevel)
325
+ Files.configureDebugging({
326
+ debugRequest: savedDebugRequest,
327
+ debugResponseHeaders: savedDebugResponseHeaders,
328
+ })
329
+
330
+ const allLogs = logs.join('\n')
331
+ invariant(allLogs.includes('"Accept-Language":"es"'), '"Accept-Language: es" header not found in debug output');
332
+
333
+ Logger.info('***** testLanguage() succeeded! *****');
334
+ }
335
+
263
336
  //
264
337
  // execute all tests
265
338
  //
@@ -273,6 +346,7 @@ const testSuite = async () => {
273
346
  await testSession()
274
347
  await testFailure()
275
348
  await testUserListAndUpdate()
349
+ await testLanguage()
276
350
  } catch (error) {
277
351
  console.log('*** TEST SUITE FAILED ***')
278
352
  console.error(error)