comprodls-sdk 2.36.0 → 2.38.0

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.
@@ -212,7 +212,8 @@ exports.AUTH_API_URLS = {
212
212
  createOrGetGradebookMeta: '/org/{orgId}/classes/{classId}/gradebooks',
213
213
  updateOrDeleteGradebookMeta: '/org/{orgId}/classes/{classId}/gradebooks/{gradebook_id}',
214
214
  gradebookColumns: '/org/{orgId}/classes/{classId}/gradebooks/{gradebook_id}/columns',
215
- updateGradebookColumn: '/org/{orgId}/classes/{classId}/gradebooks/{gradebook_id}/columns/{column_id}'
215
+ getAllClassesOfAComponent: '/org/{orgId}/components/{component_code}/classes',
216
+ removeAllGradebookColumnsOfAComponent: '/org/{orgId}/gradebook/columns/custom-components/{component_code}'
216
217
  };
217
218
 
218
219
  exports.ACTIVITY_API_URLS = {
@@ -48,6 +48,7 @@ function auth() {
48
48
  pisImport: pisImport.bind(this),
49
49
 
50
50
  getAllUsers: getAllUsers.bind(this),
51
+ getAllUsersV2: getAllUsersV2.bind(this),
51
52
  getUserProfile: getUserProfile.bind(this),
52
53
  deleteUserProfile: deleteUserProfile.bind(this),
53
54
  updateUserRole: updateUserRole.bind(this),
@@ -111,10 +112,12 @@ function auth() {
111
112
  getParticularGradebookMetaOfAClass: getParticularGradebookMetaOfAClass.bind(this),
112
113
  getAllGradebooksMetaOfAClass: getAllGradebooksMetaOfAClass.bind(this),
113
114
  addGradebookColumns: addGradebookColumns.bind(this),
114
- updateGradebookColumn: updateGradebookColumn.bind(this),
115
+ updateMultipleGradebookColumns: updateMultipleGradebookColumns.bind(this),
115
116
  removeGradebookColumns: removeGradebookColumns.bind(this),
116
117
  getParticularColumnOfAGradebook: getParticularColumnOfAGradebook.bind(this),
117
- getAllColumnsOfAGradebook: getAllColumnsOfAGradebook.bind(this)
118
+ getAllColumnsOfAGradebook: getAllColumnsOfAGradebook.bind(this),
119
+ getAllClassesOfAComponent: getAllClassesOfAComponent.bind(this),
120
+ removeAllGradebookColumnsOfAComponent: removeAllGradebookColumnsOfAComponent.bind(this)
118
121
  };
119
122
  }
120
123
 
@@ -361,6 +364,218 @@ function getAllUsers(options) {
361
364
  return dfd.promise;
362
365
  }
363
366
 
367
+ /**
368
+ * This function is used to fetch all the users of a particular org.
369
+ * Params:
370
+ * {
371
+ * role: 'string' // Optional
372
+ * lookup: 'string', // Optional. Search query (',' separated key-value pairs)
373
+ * lookup-operator: 'string', // Optional. Default - 'OR'. Permitted values - [OR]
374
+ * sortField: 'string', // Default - 'last_name'.
375
+ * sortOrder: 'string', // Default - 'desc'. Permitted values - [desc, asc]
376
+ * limit: number, // Optional. Default - 10
377
+ * cursor: '<cursor>' // Optional
378
+ * }
379
+ * @param {*} options
380
+ */
381
+ function getAllUsersV2(options) {
382
+ var self = this;
383
+
384
+ // Initializing promise
385
+ var deferred = q.defer();
386
+
387
+ // Validations
388
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
389
+ if (error) {
390
+ deferred.reject(error);
391
+ } else {
392
+ // Initialize query object.
393
+ var queryObject = {
394
+ query: { bool: { must: [] } },
395
+ size: options.limit || 10 // (DEFAULT) ES returns only 10 elements at max.
396
+ };
397
+
398
+ // Prepare query_string for fetching all the users of a particular school (org).
399
+ var queryStr = 'orgid:"' + self.orgId + '"';
400
+
401
+ // Update the query_string to filter the users based on their user-role.
402
+ if (options.role) {
403
+ var roleNameString, roleNameArray;
404
+
405
+ roleNameString = options.role;
406
+ roleNameArray = roleNameString.split(',').map(function (item) {
407
+ return item.trim();
408
+ });
409
+
410
+ for (var idx in roleNameArray) {
411
+ roleNameArray[idx] = 'roles:' + roleNameArray[idx];
412
+ }
413
+ queryStr = queryStr + ' AND (' + roleNameArray.join(' OR ') + ')';
414
+ }
415
+
416
+ // Update the queryObject with the query_string.
417
+ queryObject.query.bool.must.push({
418
+ query_string: { query: queryStr }
419
+ });
420
+
421
+ // Update the queryObject to filter the users based on lookup's key-value pairs.
422
+ if (options.lookup && options['lookup-operator']) {
423
+ var lookupString, lookupArray;
424
+
425
+ // Update the 'lookupString' to remove the prefix 'ext_' from keys of the key-value pairs.
426
+ lookupString = options.lookup.replace(/ext_/ig, '');
427
+ lookupArray = lookupString.split(',');
428
+
429
+ // Iterate over all the key-value pairs and prepare lookupOptions.
430
+ var lookupOptions = { bool: {} };
431
+ for (var index in lookupArray) {
432
+ var lookupItem = lookupArray[index].trim(),
433
+ tempArr = lookupItem.split(':'),
434
+ lookupObject = { wildcard: {} },
435
+ lookupKey, lookupValue;
436
+
437
+ /**
438
+ * The suffix '.keyword' is ONLY required for fields of type 'string'.
439
+ * Note: Currently lookup is ONLY supported for fields of type 'string'.
440
+ */
441
+ lookupKey = tempArr[0] + '.keyword';
442
+ lookupValue = tempArr[1];
443
+
444
+ // Case-insensitive lookup is currently ONLY SUPPORTED on the field 'ext_email'.
445
+ if (lookupKey === 'email.keyword') {
446
+ lookupObject.wildcard[lookupKey] = { value: lookupValue, case_insensitive: true };
447
+ } else {
448
+ lookupObject.wildcard[lookupKey] = { value: lookupValue, case_insensitive: false };
449
+ }
450
+
451
+ if (options['lookup-operator'] === 'OR') {
452
+ if (!lookupOptions.bool.should) { lookupOptions.bool.should = []; }
453
+ lookupOptions.bool.should.push(lookupObject);
454
+ } else {
455
+ /**
456
+ * If the 'lookup-operator' is 'AND', use the 'must' clause.
457
+ * Note: This value is currently NOT SUPPORTED.
458
+ * Prepare error and reject the request.
459
+ */
460
+ var errMsg = 'The value \'AND\' for the field \'lookup-operator\' is currently NOT supported';
461
+ error = {};
462
+ error.message = error.description = errMsg;
463
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
464
+
465
+ deferred.reject(error);
466
+ return deferred.promise;
467
+ }
468
+ }
469
+ queryObject.query.bool.must.push(lookupOptions);
470
+ }
471
+
472
+ // Update the queryObject to sort the results based on sortField / sortOrder.
473
+ var sortField, sortOrder, sortObj = {}, sortArr = [];
474
+ sortField = options.sortField || 'last_name';
475
+ sortOrder = options.sortOrder || 'asc';
476
+
477
+ // Update the sortField to remove prefix: 'ext_' and trim any unnecessary whitespaces.
478
+ sortField = sortField.replace(/ext_/ig, '').split(',').shift().trim();
479
+ if (sortField !== 'created') {
480
+ sortField = sortField + '.keyword';
481
+ }
482
+
483
+ sortObj[sortField] = sortOrder;
484
+ sortArr.push(sortObj);
485
+ queryObject.sort = sortArr;
486
+
487
+ // Update the queryObject to fetch the next set of records from ES.
488
+ if (options.cursor) {
489
+ queryObject.search_after = JSON.parse(options.cursor);
490
+ }
491
+
492
+ // Passed all validations, Construct API URL
493
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.queryDataFromSearch;
494
+ url = helpers.api.constructAPIUrl(url, { index: 'users' });
495
+
496
+ // Setup request with URL and Params
497
+ var params = { query: JSON.stringify(queryObject)};
498
+ var requestAPI = request.get(url).query(params);
499
+ if (self.traceid) {
500
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
501
+ }
502
+
503
+ // Setup token in Authorization header
504
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
505
+
506
+ // Call the ES API to fetch users from ES.
507
+ requestAPI.end(function (err, response) {
508
+ if (err) {
509
+ // Prepare and send error response.
510
+ var esErrOptions = { type: helpers.errors.ERROR_TYPES.API_ERROR, err: err },
511
+ error = converter.convertElasticsearchErrResponse(esErrOptions);
512
+
513
+ deferred.reject(error);
514
+ } else {
515
+ // Prepare and send success response.
516
+ var responseObject = {
517
+ entities: [], count: response.body.hits.hits.length
518
+ };
519
+
520
+ if (responseObject.count && options.limit === responseObject.count) {
521
+ var cursor = response.body.hits.hits[response.body.hits.hits.length - 1].sort;
522
+ responseObject.cursor = JSON.stringify(cursor);
523
+ }
524
+
525
+ for (var index in response.body.hits.hits) {
526
+ var userEntity = response.body.hits.hits[index]._source,
527
+ userObj = {
528
+ uuid: userEntity.dls_user_id,
529
+ name: userEntity.first_name + ' ' + userEntity.last_name,
530
+ email: userEntity.email || userEntity.ext_email,
531
+ username: userEntity.userid + '--ACCOUNT',
532
+ created: userEntity.created,
533
+ org: { id: self.orgId }
534
+ };
535
+
536
+ if (userEntity.roles) {
537
+ userObj.roles = userEntity.roles;
538
+ }
539
+
540
+ if (userEntity.provision_method) {
541
+ userObj.provision_method = userEntity.provision_method;
542
+ }
543
+
544
+ if (userEntity.first_name) {
545
+ userObj.first_name = userEntity.first_name;
546
+ }
547
+
548
+ if (userEntity.last_name) {
549
+ userObj.last_name = userEntity.last_name;
550
+ }
551
+
552
+ if (userEntity.ext_parent_id) {
553
+ userObj.ext_parent_id = userEntity.ext_parent_id;
554
+ }
555
+
556
+ if (userEntity.username) {
557
+ userObj.ext_username = userEntity.username;
558
+ }
559
+
560
+ if (userEntity.userid) {
561
+ userObj.ext_user_id = userEntity.userid;
562
+ }
563
+
564
+ if (userEntity.address) {
565
+ userObj.address = userEntity.address;
566
+ }
567
+
568
+ responseObject.entities.push(userObj);
569
+ }
570
+
571
+ deferred.resolve(responseObject);
572
+ }
573
+ });
574
+ }
575
+
576
+ return deferred.promise;
577
+ }
578
+
364
579
  //options = {
365
580
  // userid: 'dlsUserId', //mandatory
366
581
  // target_role: 'string', //mandatory
@@ -3181,20 +3396,24 @@ function addGradebookColumns(options) {
3181
3396
  options = {
3182
3397
  classid: "string", //mandatory
3183
3398
  gradebook_id: "string", //mandatory
3184
- column_id: "string", //mandatory
3185
3399
  body : {
3186
- "title": "string",
3187
- "weightage": "string",
3188
- "items": [
3400
+ "columns": [
3189
3401
  {
3190
- "item-code": "string"
3191
- }
3192
- ],
3193
- "data": {...}
3402
+ "title": "string",
3403
+ "weightage": "string",
3404
+ "items": [
3405
+ {
3406
+ "item-code": "string"
3407
+ }
3408
+ ],
3409
+ "data": {...}
3410
+ },
3411
+ {...}
3412
+ ]
3194
3413
  }
3195
3414
  }
3196
3415
  */
3197
- function updateGradebookColumn(options) {
3416
+ function updateMultipleGradebookColumns(options) {
3198
3417
  // Initializing promise
3199
3418
  var deferred = q.defer();
3200
3419
  var self = this;
@@ -3205,49 +3424,42 @@ function updateGradebookColumn(options) {
3205
3424
  if(err) {
3206
3425
  deferred.reject(err);
3207
3426
  } else {
3208
- if (options && options.classid && options.gradebook_id && options.column_id && options.body) {
3209
- if (Object.keys(options.body).length !== 0) {
3210
- // Passed all validations, Contruct API url
3211
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.updateGradebookColumn;
3427
+ if (options && options.classid && options.gradebook_id && options.body && options.body.columns) {
3428
+ // Passed all validations, Contruct API url
3429
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.gradebookColumns;
3212
3430
 
3213
- url = helpers.api.constructAPIUrl(url, {
3214
- orgId: self.orgId,
3215
- classId: options.classid,
3216
- gradebook_id: options.gradebook_id,
3217
- column_id: options.column_id
3218
- });
3431
+ url = helpers.api.constructAPIUrl(url, {
3432
+ orgId: self.orgId,
3433
+ classId: options.classid,
3434
+ gradebook_id: options.gradebook_id
3435
+ });
3219
3436
 
3220
- var params = options.body;
3221
- // Setup request with URL and Params
3222
- var requestAPI = request.put(url)
3223
- .set('Content-Type', 'application/json')
3224
- .set('Accept', 'application/json')
3225
- .send(params);
3437
+ var params = options.body;
3438
+ // Setup request with URL and Params
3439
+ var requestAPI = request.put(url)
3440
+ .set('Content-Type', 'application/json')
3441
+ .set('Accept', 'application/json')
3442
+ .send(params);
3226
3443
 
3227
- if (self.traceid) {
3228
- requestAPI.set('X-Amzn-Trace-Id', self.traceid);
3229
- }
3444
+ if (self.traceid) {
3445
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
3446
+ }
3230
3447
 
3231
- //Setup token in Authorization header
3232
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
3448
+ //Setup token in Authorization header
3449
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
3233
3450
 
3234
- requestAPI
3235
- .agent(keepaliveAgent)
3236
- .end(function(error, response) {
3237
- if (error) {
3238
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
3239
- deferred.reject(error);
3240
- } else {
3241
- deferred.resolve(response.body);
3242
- }
3243
- });
3244
- } else {
3245
- error.message = error.description = 'Body of the request input cannot be empty.';
3246
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
3247
- deferred.reject(error);
3248
- }
3451
+ requestAPI
3452
+ .agent(keepaliveAgent)
3453
+ .end(function(error, response) {
3454
+ if (error) {
3455
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
3456
+ deferred.reject(error);
3457
+ } else {
3458
+ deferred.resolve(response.body);
3459
+ }
3460
+ });
3249
3461
  } else {
3250
- error.message = error.description = 'Mandatory params: classid, gradebook_id, column_id or body' +
3462
+ error.message = error.description = 'Mandatory params: classid, gradebook_id, body or body.columns' +
3251
3463
  ' not found in the request options.';
3252
3464
  error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
3253
3465
  deferred.reject(error);
@@ -3430,3 +3642,122 @@ function getAllColumnsOfAGradebook (options) {
3430
3642
  }
3431
3643
  return deferred.promise;
3432
3644
  }
3645
+
3646
+ /*
3647
+ options = {
3648
+ component_code: "string", //mandatory
3649
+ cursor: "string" //optional
3650
+ }
3651
+ */
3652
+ function getAllClassesOfAComponent (options) {
3653
+ // Initializing promise
3654
+ var deferred = q.defer();
3655
+ var self = this;
3656
+ var error = {};
3657
+
3658
+ //Validations
3659
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
3660
+ if(err) {
3661
+ deferred.reject(err);
3662
+ } else {
3663
+ if (options && options.component_code) {
3664
+ // Passed all validations, Contruct API url
3665
+ var url = self.config.DEFAULT_HOSTS.AUTH +
3666
+ self.config.AUTH_API_URLS.getAllClassesOfAComponent;
3667
+
3668
+ url = helpers.api.constructAPIUrl(url, {
3669
+ orgId: self.orgId,
3670
+ component_code: options.component_code
3671
+ });
3672
+
3673
+ var params = {};
3674
+ if(options.cursor){ params.cursor = options.cursor; }
3675
+
3676
+ var requestAPI = request.get(url).query(params);
3677
+
3678
+ if (self.traceid) {
3679
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
3680
+ }
3681
+
3682
+ //Setup token in Authorization header
3683
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
3684
+
3685
+ requestAPI
3686
+ .agent(keepaliveAgent)
3687
+ .end(function(error, response) {
3688
+ if (error) {
3689
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
3690
+ deferred.reject(error);
3691
+ } else {
3692
+ deferred.resolve(response.body);
3693
+ }
3694
+ });
3695
+ } else {
3696
+ error.message = error.description = 'Mandatory params: component_code' +
3697
+ ' not found in the request options.';
3698
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
3699
+ deferred.reject(error);
3700
+ }
3701
+ }
3702
+ return deferred.promise;
3703
+ }
3704
+
3705
+ /*
3706
+ options = {
3707
+ component_code: "string" //mandatory
3708
+ }
3709
+ */
3710
+ function removeAllGradebookColumnsOfAComponent (options) {
3711
+ // Initializing promise
3712
+ var deferred = q.defer();
3713
+ var self = this;
3714
+ var error = {};
3715
+
3716
+ //Validations
3717
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
3718
+ if(err) {
3719
+ deferred.reject(err);
3720
+ } else {
3721
+ if (options && options.component_code) {
3722
+ // Passed all validations, Contruct API url
3723
+ var url = self.config.DEFAULT_HOSTS.AUTH +
3724
+ self.config.AUTH_API_URLS.removeAllGradebookColumnsOfAComponent;
3725
+
3726
+ url = helpers.api.constructAPIUrl(url, {
3727
+ orgId: self.orgId,
3728
+ component_code: options.component_code
3729
+ });
3730
+
3731
+ // Setup request with URL and Params
3732
+ var requestAPI = request
3733
+ .delete(url)
3734
+ .set('Content-Type', 'application/json')
3735
+ .set('Accept', 'application/json')
3736
+ .send(options.body);
3737
+
3738
+ if (self.traceid) {
3739
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
3740
+ }
3741
+
3742
+ //Setup token in Authorization header
3743
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
3744
+
3745
+ requestAPI
3746
+ .agent(keepaliveAgent)
3747
+ .end(function(error, response) {
3748
+ if (error) {
3749
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
3750
+ deferred.reject(error);
3751
+ } else {
3752
+ deferred.resolve(response.body);
3753
+ }
3754
+ });
3755
+ } else {
3756
+ error.message = error.description = 'Mandatory params: component_code' +
3757
+ ' not found in the request options.';
3758
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
3759
+ deferred.reject(error);
3760
+ }
3761
+ }
3762
+ return deferred.promise;
3763
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "comprodls-sdk",
3
3
  "description": "comproDLS SDK for JavaScript",
4
- "version": "2.36.0",
4
+ "version": "2.38.0",
5
5
  "author": {
6
6
  "name": "Compro Technologies Private Limited",
7
7
  "url": "http://www.comprotechnologies.com/"