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.
@@ -367,7 +367,8 @@ exports.AUTH_API_URLS = {
367
367
  createOrGetGradebookMeta: '/org/{orgId}/classes/{classId}/gradebooks',
368
368
  updateOrDeleteGradebookMeta: '/org/{orgId}/classes/{classId}/gradebooks/{gradebook_id}',
369
369
  gradebookColumns: '/org/{orgId}/classes/{classId}/gradebooks/{gradebook_id}/columns',
370
- updateGradebookColumn: '/org/{orgId}/classes/{classId}/gradebooks/{gradebook_id}/columns/{column_id}'
370
+ getAllClassesOfAComponent: '/org/{orgId}/components/{component_code}/classes',
371
+ removeAllGradebookColumnsOfAComponent: '/org/{orgId}/gradebook/columns/custom-components/{component_code}'
371
372
  };
372
373
 
373
374
  exports.ACTIVITY_API_URLS = {
@@ -4077,6 +4078,7 @@ function auth() {
4077
4078
  pisImport: pisImport.bind(this),
4078
4079
 
4079
4080
  getAllUsers: getAllUsers.bind(this),
4081
+ getAllUsersV2: getAllUsersV2.bind(this),
4080
4082
  getUserProfile: getUserProfile.bind(this),
4081
4083
  deleteUserProfile: deleteUserProfile.bind(this),
4082
4084
  updateUserRole: updateUserRole.bind(this),
@@ -4140,10 +4142,12 @@ function auth() {
4140
4142
  getParticularGradebookMetaOfAClass: getParticularGradebookMetaOfAClass.bind(this),
4141
4143
  getAllGradebooksMetaOfAClass: getAllGradebooksMetaOfAClass.bind(this),
4142
4144
  addGradebookColumns: addGradebookColumns.bind(this),
4143
- updateGradebookColumn: updateGradebookColumn.bind(this),
4145
+ updateMultipleGradebookColumns: updateMultipleGradebookColumns.bind(this),
4144
4146
  removeGradebookColumns: removeGradebookColumns.bind(this),
4145
4147
  getParticularColumnOfAGradebook: getParticularColumnOfAGradebook.bind(this),
4146
- getAllColumnsOfAGradebook: getAllColumnsOfAGradebook.bind(this)
4148
+ getAllColumnsOfAGradebook: getAllColumnsOfAGradebook.bind(this),
4149
+ getAllClassesOfAComponent: getAllClassesOfAComponent.bind(this),
4150
+ removeAllGradebookColumnsOfAComponent: removeAllGradebookColumnsOfAComponent.bind(this)
4147
4151
  };
4148
4152
  }
4149
4153
 
@@ -4390,6 +4394,218 @@ function getAllUsers(options) {
4390
4394
  return dfd.promise;
4391
4395
  }
4392
4396
 
4397
+ /**
4398
+ * This function is used to fetch all the users of a particular org.
4399
+ * Params:
4400
+ * {
4401
+ * role: 'string' // Optional
4402
+ * lookup: 'string', // Optional. Search query (',' separated key-value pairs)
4403
+ * lookup-operator: 'string', // Optional. Default - 'OR'. Permitted values - [OR]
4404
+ * sortField: 'string', // Default - 'last_name'.
4405
+ * sortOrder: 'string', // Default - 'desc'. Permitted values - [desc, asc]
4406
+ * limit: number, // Optional. Default - 10
4407
+ * cursor: '<cursor>' // Optional
4408
+ * }
4409
+ * @param {*} options
4410
+ */
4411
+ function getAllUsersV2(options) {
4412
+ var self = this;
4413
+
4414
+ // Initializing promise
4415
+ var deferred = q.defer();
4416
+
4417
+ // Validations
4418
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
4419
+ if (error) {
4420
+ deferred.reject(error);
4421
+ } else {
4422
+ // Initialize query object.
4423
+ var queryObject = {
4424
+ query: { bool: { must: [] } },
4425
+ size: options.limit || 10 // (DEFAULT) ES returns only 10 elements at max.
4426
+ };
4427
+
4428
+ // Prepare query_string for fetching all the users of a particular school (org).
4429
+ var queryStr = 'orgid:"' + self.orgId + '"';
4430
+
4431
+ // Update the query_string to filter the users based on their user-role.
4432
+ if (options.role) {
4433
+ var roleNameString, roleNameArray;
4434
+
4435
+ roleNameString = options.role;
4436
+ roleNameArray = roleNameString.split(',').map(function (item) {
4437
+ return item.trim();
4438
+ });
4439
+
4440
+ for (var idx in roleNameArray) {
4441
+ roleNameArray[idx] = 'roles:' + roleNameArray[idx];
4442
+ }
4443
+ queryStr = queryStr + ' AND (' + roleNameArray.join(' OR ') + ')';
4444
+ }
4445
+
4446
+ // Update the queryObject with the query_string.
4447
+ queryObject.query.bool.must.push({
4448
+ query_string: { query: queryStr }
4449
+ });
4450
+
4451
+ // Update the queryObject to filter the users based on lookup's key-value pairs.
4452
+ if (options.lookup && options['lookup-operator']) {
4453
+ var lookupString, lookupArray;
4454
+
4455
+ // Update the 'lookupString' to remove the prefix 'ext_' from keys of the key-value pairs.
4456
+ lookupString = options.lookup.replace(/ext_/ig, '');
4457
+ lookupArray = lookupString.split(',');
4458
+
4459
+ // Iterate over all the key-value pairs and prepare lookupOptions.
4460
+ var lookupOptions = { bool: {} };
4461
+ for (var index in lookupArray) {
4462
+ var lookupItem = lookupArray[index].trim(),
4463
+ tempArr = lookupItem.split(':'),
4464
+ lookupObject = { wildcard: {} },
4465
+ lookupKey, lookupValue;
4466
+
4467
+ /**
4468
+ * The suffix '.keyword' is ONLY required for fields of type 'string'.
4469
+ * Note: Currently lookup is ONLY supported for fields of type 'string'.
4470
+ */
4471
+ lookupKey = tempArr[0] + '.keyword';
4472
+ lookupValue = tempArr[1];
4473
+
4474
+ // Case-insensitive lookup is currently ONLY SUPPORTED on the field 'ext_email'.
4475
+ if (lookupKey === 'email.keyword') {
4476
+ lookupObject.wildcard[lookupKey] = { value: lookupValue, case_insensitive: true };
4477
+ } else {
4478
+ lookupObject.wildcard[lookupKey] = { value: lookupValue, case_insensitive: false };
4479
+ }
4480
+
4481
+ if (options['lookup-operator'] === 'OR') {
4482
+ if (!lookupOptions.bool.should) { lookupOptions.bool.should = []; }
4483
+ lookupOptions.bool.should.push(lookupObject);
4484
+ } else {
4485
+ /**
4486
+ * If the 'lookup-operator' is 'AND', use the 'must' clause.
4487
+ * Note: This value is currently NOT SUPPORTED.
4488
+ * Prepare error and reject the request.
4489
+ */
4490
+ var errMsg = 'The value \'AND\' for the field \'lookup-operator\' is currently NOT supported';
4491
+ error = {};
4492
+ error.message = error.description = errMsg;
4493
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
4494
+
4495
+ deferred.reject(error);
4496
+ return deferred.promise;
4497
+ }
4498
+ }
4499
+ queryObject.query.bool.must.push(lookupOptions);
4500
+ }
4501
+
4502
+ // Update the queryObject to sort the results based on sortField / sortOrder.
4503
+ var sortField, sortOrder, sortObj = {}, sortArr = [];
4504
+ sortField = options.sortField || 'last_name';
4505
+ sortOrder = options.sortOrder || 'asc';
4506
+
4507
+ // Update the sortField to remove prefix: 'ext_' and trim any unnecessary whitespaces.
4508
+ sortField = sortField.replace(/ext_/ig, '').split(',').shift().trim();
4509
+ if (sortField !== 'created') {
4510
+ sortField = sortField + '.keyword';
4511
+ }
4512
+
4513
+ sortObj[sortField] = sortOrder;
4514
+ sortArr.push(sortObj);
4515
+ queryObject.sort = sortArr;
4516
+
4517
+ // Update the queryObject to fetch the next set of records from ES.
4518
+ if (options.cursor) {
4519
+ queryObject.search_after = JSON.parse(options.cursor);
4520
+ }
4521
+
4522
+ // Passed all validations, Construct API URL
4523
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.queryDataFromSearch;
4524
+ url = helpers.api.constructAPIUrl(url, { index: 'users' });
4525
+
4526
+ // Setup request with URL and Params
4527
+ var params = { query: JSON.stringify(queryObject)};
4528
+ var requestAPI = request.get(url).query(params);
4529
+ if (self.traceid) {
4530
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
4531
+ }
4532
+
4533
+ // Setup token in Authorization header
4534
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
4535
+
4536
+ // Call the ES API to fetch users from ES.
4537
+ requestAPI.end(function (err, response) {
4538
+ if (err) {
4539
+ // Prepare and send error response.
4540
+ var esErrOptions = { type: helpers.errors.ERROR_TYPES.API_ERROR, err: err },
4541
+ error = converter.convertElasticsearchErrResponse(esErrOptions);
4542
+
4543
+ deferred.reject(error);
4544
+ } else {
4545
+ // Prepare and send success response.
4546
+ var responseObject = {
4547
+ entities: [], count: response.body.hits.hits.length
4548
+ };
4549
+
4550
+ if (responseObject.count && options.limit === responseObject.count) {
4551
+ var cursor = response.body.hits.hits[response.body.hits.hits.length - 1].sort;
4552
+ responseObject.cursor = JSON.stringify(cursor);
4553
+ }
4554
+
4555
+ for (var index in response.body.hits.hits) {
4556
+ var userEntity = response.body.hits.hits[index]._source,
4557
+ userObj = {
4558
+ uuid: userEntity.dls_user_id,
4559
+ name: userEntity.first_name + ' ' + userEntity.last_name,
4560
+ email: userEntity.email || userEntity.ext_email,
4561
+ username: userEntity.userid + '--ACCOUNT',
4562
+ created: userEntity.created,
4563
+ org: { id: self.orgId }
4564
+ };
4565
+
4566
+ if (userEntity.roles) {
4567
+ userObj.roles = userEntity.roles;
4568
+ }
4569
+
4570
+ if (userEntity.provision_method) {
4571
+ userObj.provision_method = userEntity.provision_method;
4572
+ }
4573
+
4574
+ if (userEntity.first_name) {
4575
+ userObj.first_name = userEntity.first_name;
4576
+ }
4577
+
4578
+ if (userEntity.last_name) {
4579
+ userObj.last_name = userEntity.last_name;
4580
+ }
4581
+
4582
+ if (userEntity.ext_parent_id) {
4583
+ userObj.ext_parent_id = userEntity.ext_parent_id;
4584
+ }
4585
+
4586
+ if (userEntity.username) {
4587
+ userObj.ext_username = userEntity.username;
4588
+ }
4589
+
4590
+ if (userEntity.userid) {
4591
+ userObj.ext_user_id = userEntity.userid;
4592
+ }
4593
+
4594
+ if (userEntity.address) {
4595
+ userObj.address = userEntity.address;
4596
+ }
4597
+
4598
+ responseObject.entities.push(userObj);
4599
+ }
4600
+
4601
+ deferred.resolve(responseObject);
4602
+ }
4603
+ });
4604
+ }
4605
+
4606
+ return deferred.promise;
4607
+ }
4608
+
4393
4609
  //options = {
4394
4610
  // userid: 'dlsUserId', //mandatory
4395
4611
  // target_role: 'string', //mandatory
@@ -7210,20 +7426,24 @@ function addGradebookColumns(options) {
7210
7426
  options = {
7211
7427
  classid: "string", //mandatory
7212
7428
  gradebook_id: "string", //mandatory
7213
- column_id: "string", //mandatory
7214
7429
  body : {
7215
- "title": "string",
7216
- "weightage": "string",
7217
- "items": [
7430
+ "columns": [
7218
7431
  {
7219
- "item-code": "string"
7220
- }
7221
- ],
7222
- "data": {...}
7432
+ "title": "string",
7433
+ "weightage": "string",
7434
+ "items": [
7435
+ {
7436
+ "item-code": "string"
7437
+ }
7438
+ ],
7439
+ "data": {...}
7440
+ },
7441
+ {...}
7442
+ ]
7223
7443
  }
7224
7444
  }
7225
7445
  */
7226
- function updateGradebookColumn(options) {
7446
+ function updateMultipleGradebookColumns(options) {
7227
7447
  // Initializing promise
7228
7448
  var deferred = q.defer();
7229
7449
  var self = this;
@@ -7234,49 +7454,42 @@ function updateGradebookColumn(options) {
7234
7454
  if(err) {
7235
7455
  deferred.reject(err);
7236
7456
  } else {
7237
- if (options && options.classid && options.gradebook_id && options.column_id && options.body) {
7238
- if (Object.keys(options.body).length !== 0) {
7239
- // Passed all validations, Contruct API url
7240
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.updateGradebookColumn;
7457
+ if (options && options.classid && options.gradebook_id && options.body && options.body.columns) {
7458
+ // Passed all validations, Contruct API url
7459
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.gradebookColumns;
7241
7460
 
7242
- url = helpers.api.constructAPIUrl(url, {
7243
- orgId: self.orgId,
7244
- classId: options.classid,
7245
- gradebook_id: options.gradebook_id,
7246
- column_id: options.column_id
7247
- });
7461
+ url = helpers.api.constructAPIUrl(url, {
7462
+ orgId: self.orgId,
7463
+ classId: options.classid,
7464
+ gradebook_id: options.gradebook_id
7465
+ });
7248
7466
 
7249
- var params = options.body;
7250
- // Setup request with URL and Params
7251
- var requestAPI = request.put(url)
7252
- .set('Content-Type', 'application/json')
7253
- .set('Accept', 'application/json')
7254
- .send(params);
7467
+ var params = options.body;
7468
+ // Setup request with URL and Params
7469
+ var requestAPI = request.put(url)
7470
+ .set('Content-Type', 'application/json')
7471
+ .set('Accept', 'application/json')
7472
+ .send(params);
7255
7473
 
7256
- if (self.traceid) {
7257
- requestAPI.set('X-Amzn-Trace-Id', self.traceid);
7258
- }
7474
+ if (self.traceid) {
7475
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
7476
+ }
7259
7477
 
7260
- //Setup token in Authorization header
7261
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
7478
+ //Setup token in Authorization header
7479
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
7262
7480
 
7263
- requestAPI
7264
- .agent(keepaliveAgent)
7265
- .end(function(error, response) {
7266
- if (error) {
7267
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
7268
- deferred.reject(error);
7269
- } else {
7270
- deferred.resolve(response.body);
7271
- }
7272
- });
7273
- } else {
7274
- error.message = error.description = 'Body of the request input cannot be empty.';
7275
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
7276
- deferred.reject(error);
7277
- }
7481
+ requestAPI
7482
+ .agent(keepaliveAgent)
7483
+ .end(function(error, response) {
7484
+ if (error) {
7485
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
7486
+ deferred.reject(error);
7487
+ } else {
7488
+ deferred.resolve(response.body);
7489
+ }
7490
+ });
7278
7491
  } else {
7279
- error.message = error.description = 'Mandatory params: classid, gradebook_id, column_id or body' +
7492
+ error.message = error.description = 'Mandatory params: classid, gradebook_id, body or body.columns' +
7280
7493
  ' not found in the request options.';
7281
7494
  error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
7282
7495
  deferred.reject(error);
@@ -7459,6 +7672,125 @@ function getAllColumnsOfAGradebook (options) {
7459
7672
  }
7460
7673
  return deferred.promise;
7461
7674
  }
7675
+
7676
+ /*
7677
+ options = {
7678
+ component_code: "string", //mandatory
7679
+ cursor: "string" //optional
7680
+ }
7681
+ */
7682
+ function getAllClassesOfAComponent (options) {
7683
+ // Initializing promise
7684
+ var deferred = q.defer();
7685
+ var self = this;
7686
+ var error = {};
7687
+
7688
+ //Validations
7689
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
7690
+ if(err) {
7691
+ deferred.reject(err);
7692
+ } else {
7693
+ if (options && options.component_code) {
7694
+ // Passed all validations, Contruct API url
7695
+ var url = self.config.DEFAULT_HOSTS.AUTH +
7696
+ self.config.AUTH_API_URLS.getAllClassesOfAComponent;
7697
+
7698
+ url = helpers.api.constructAPIUrl(url, {
7699
+ orgId: self.orgId,
7700
+ component_code: options.component_code
7701
+ });
7702
+
7703
+ var params = {};
7704
+ if(options.cursor){ params.cursor = options.cursor; }
7705
+
7706
+ var requestAPI = request.get(url).query(params);
7707
+
7708
+ if (self.traceid) {
7709
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
7710
+ }
7711
+
7712
+ //Setup token in Authorization header
7713
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
7714
+
7715
+ requestAPI
7716
+ .agent(keepaliveAgent)
7717
+ .end(function(error, response) {
7718
+ if (error) {
7719
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
7720
+ deferred.reject(error);
7721
+ } else {
7722
+ deferred.resolve(response.body);
7723
+ }
7724
+ });
7725
+ } else {
7726
+ error.message = error.description = 'Mandatory params: component_code' +
7727
+ ' not found in the request options.';
7728
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
7729
+ deferred.reject(error);
7730
+ }
7731
+ }
7732
+ return deferred.promise;
7733
+ }
7734
+
7735
+ /*
7736
+ options = {
7737
+ component_code: "string" //mandatory
7738
+ }
7739
+ */
7740
+ function removeAllGradebookColumnsOfAComponent (options) {
7741
+ // Initializing promise
7742
+ var deferred = q.defer();
7743
+ var self = this;
7744
+ var error = {};
7745
+
7746
+ //Validations
7747
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
7748
+ if(err) {
7749
+ deferred.reject(err);
7750
+ } else {
7751
+ if (options && options.component_code) {
7752
+ // Passed all validations, Contruct API url
7753
+ var url = self.config.DEFAULT_HOSTS.AUTH +
7754
+ self.config.AUTH_API_URLS.removeAllGradebookColumnsOfAComponent;
7755
+
7756
+ url = helpers.api.constructAPIUrl(url, {
7757
+ orgId: self.orgId,
7758
+ component_code: options.component_code
7759
+ });
7760
+
7761
+ // Setup request with URL and Params
7762
+ var requestAPI = request
7763
+ .delete(url)
7764
+ .set('Content-Type', 'application/json')
7765
+ .set('Accept', 'application/json')
7766
+ .send(options.body);
7767
+
7768
+ if (self.traceid) {
7769
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
7770
+ }
7771
+
7772
+ //Setup token in Authorization header
7773
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
7774
+
7775
+ requestAPI
7776
+ .agent(keepaliveAgent)
7777
+ .end(function(error, response) {
7778
+ if (error) {
7779
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
7780
+ deferred.reject(error);
7781
+ } else {
7782
+ deferred.resolve(response.body);
7783
+ }
7784
+ });
7785
+ } else {
7786
+ error.message = error.description = 'Mandatory params: component_code' +
7787
+ ' not found in the request options.';
7788
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
7789
+ deferred.reject(error);
7790
+ }
7791
+ }
7792
+ return deferred.promise;
7793
+ }
7462
7794
 
7463
7795
  },{"../../helpers":3,"../../helpers/lib/api/converter":4,"agentkeepalive":38,"q":91,"superagent":134}],17:[function(require,module,exports){
7464
7796
  /*************************************************************************