comprodls-sdk 2.16.0 → 2.19.1

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.
@@ -197,6 +197,7 @@ exports.AUTH_API_URLS = {
197
197
  getInvitationsByEmail: '/accounts/{accountid}/invitations-by-email',
198
198
  generateSpaceCode: '/accounts/{accountid}/space-code/generate',
199
199
  changeSpaceCode: '/accounts/{accountid}/space-code/{spacecode}/change',
200
+ updateInstituteTitle: '/accounts/{accountId}/institute-spaces/{instituteSpaceCode}',
200
201
 
201
202
  //Superuser related API
202
203
  getAllInstitutions: '/su/accounts/{accountid}/spaces',
@@ -304,7 +305,8 @@ exports.PRODUCT_API_URLS = {
304
305
 
305
306
  exports.XAPI_API_URLS = {
306
307
  postMultiStatements: '/{orgId}/statements/multi',
307
- postExternalMultiStatements: '/{orgId}/external/statements/multi'
308
+ postExternalMultiStatements: '/{orgId}/external/statements/multi',
309
+ resetUserProductProgress: '/accounts/{accountId}/progress/user/product/reset'
308
310
  };
309
311
 
310
312
  exports.ATTEMPTS_API_URLS = {
@@ -29,12 +29,18 @@
29
29
 
30
30
  var q = require('q');
31
31
  var request = require('superagent');
32
+ var Agent = require('agentkeepalive');
32
33
 
33
34
  var helpers = require('../../helpers');
34
35
  var DLSError = helpers.errors.DLSError;
35
36
 
36
37
  module.exports = analytics;
37
38
 
39
+ var keepaliveAgent = new Agent({
40
+ timeout: 60000,
41
+ keepAliveTimeout: 30000
42
+ });
43
+
38
44
  /*********************************
39
45
  * Public Function definitions
40
46
  **********************************/
@@ -1582,13 +1588,15 @@ function getTimeseriesAnalytics(options) {
1582
1588
 
1583
1589
  if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
1584
1590
 
1585
- requestAPI.end(function (error, response) {
1586
- if(error) {
1587
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
1588
- dfd.reject(err);
1589
- }
1590
- else { dfd.resolve(response.body); }
1591
- });
1591
+ requestAPI
1592
+ .agent(keepaliveAgent)
1593
+ .end(function (error, response) {
1594
+ if(error) {
1595
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
1596
+ dfd.reject(err);
1597
+ }
1598
+ else { dfd.resolve(response.body); }
1599
+ });
1592
1600
  }
1593
1601
  else {
1594
1602
  err = {};
@@ -25,6 +25,7 @@
25
25
 
26
26
  var q = require('q');
27
27
  var request = require('superagent');
28
+ var Agent = require('agentkeepalive');
28
29
 
29
30
  var helpers = require('../../helpers');
30
31
  var converter = require('../../helpers/lib/api/converter');
@@ -35,6 +36,12 @@ var DLSError = helpers.errors.DLSError;
35
36
  * Setting Up Module Entry Point
36
37
  **********************************/
37
38
  module.exports = auth;
39
+
40
+ var keepaliveAgent = new Agent({
41
+ timeout: 60000,
42
+ keepAliveTimeout: 30000
43
+ });
44
+
38
45
  //Auth Adaptor Contsructor
39
46
  function auth() {
40
47
  return {
@@ -491,16 +498,18 @@ function getClassUsers(options) {
491
498
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
492
499
 
493
500
  // Call GET ALL USER Api
494
- requestAPI.end(function(err, response) {
495
- if(err) {
496
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
497
- dfd.reject(err);
498
- }
499
- else {
500
- response.body.entities = converter.convertEnrollmetsResponse({data: response.body.entities}) ;
501
- dfd.resolve(response.body);
502
- }
503
- });
501
+ requestAPI
502
+ .agent(keepaliveAgent)
503
+ .end(function(err, response) {
504
+ if(err) {
505
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
506
+ dfd.reject(err);
507
+ }
508
+ else {
509
+ response.body.entities = converter.convertEnrollmetsResponse({data: response.body.entities}) ;
510
+ dfd.resolve(response.body);
511
+ }
512
+ });
504
513
  } else {
505
514
  err = {};
506
515
  err.message = err.description = 'Required parameter classid is not defined.';
@@ -909,14 +918,16 @@ function getParticularClass(options) {
909
918
  //Setup token in Authorization header
910
919
  requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
911
920
 
912
- requestAPI.end(function(err, response) {
913
- if(err) {
914
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
915
- dfd.reject(err);
916
- } else {
917
- dfd.resolve(response.body);
918
- }
919
- });
921
+ requestAPI
922
+ .agent(keepaliveAgent)
923
+ .end(function(err, response) {
924
+ if(err) {
925
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
926
+ dfd.reject(err);
927
+ } else {
928
+ dfd.resolve(response.body);
929
+ }
930
+ });
920
931
  } else {
921
932
  err = {};
922
933
  err.message = err.description = 'classId not found in request options.';
@@ -1314,6 +1325,7 @@ function enrollUsertoClass(options) {
1314
1325
 
1315
1326
  //options = {
1316
1327
  // classid: '', //Class Id
1328
+ // classrole: ''
1317
1329
  //};
1318
1330
  function enrollSelftoClass(options) {
1319
1331
  var self = this;
@@ -1334,8 +1346,13 @@ function enrollSelftoClass(options) {
1334
1346
  classId: options.classid
1335
1347
  });
1336
1348
 
1349
+ var params = { classrole: options.classrole };
1337
1350
  //Setup request with URL and Params
1338
- var requestAPI = request.post(url);
1351
+ var requestAPI = request.post(url)
1352
+ .set('Content-Type', 'application/json')
1353
+ .set('Accept', 'application/json')
1354
+ .send(params);
1355
+
1339
1356
  if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
1340
1357
 
1341
1358
  //Setup token in Authorization header
@@ -1538,8 +1555,9 @@ function encodeURLParameter(options) {
1538
1555
  * title: 'class title',
1539
1556
  * startdate: 'Epoch(Unix) timestamp in milliseconds',
1540
1557
  * enddate: 'Epoch(Unix) timestamp in milliseconds',
1541
- * description: '' // Optional field
1542
- * class_ownership: 'STRICT' / 'NO_OWNER' // Default - STRICT, Optional field
1558
+ * description: '', // Optional field
1559
+ * class_ownership: 'STRICT' / 'NO_OWNER', // Default - STRICT, Optional field
1560
+ * ext_data: {} // Optional
1543
1561
  * }
1544
1562
  */
1545
1563
  function createClass(options) {
@@ -1599,7 +1617,8 @@ function createClass(options) {
1599
1617
  // title: 'class title', //Optional field
1600
1618
  // startdate: 'Epoch(Unix) timestamp in milliseconds', //Optional field
1601
1619
  // enddate: 'Epoch(Unix) timestamp in milliseconds', //Optional field
1602
- // description: '' //Optional field
1620
+ // description: '', //Optional field
1621
+ // ext_data: '' //Optional field
1603
1622
  //}
1604
1623
  function updateClass(options) {
1605
1624
  var self = this;
@@ -1650,13 +1669,14 @@ function updateClass(options) {
1650
1669
  /** options =
1651
1670
  *{
1652
1671
  "space_title": "string",
1653
- "classes": [
1672
+ "classes": [
1654
1673
  {
1655
1674
  "title": "class tiltle",
1656
1675
  "startdate": 'Epoch(Unix) timestamp in milliseconds',
1657
1676
  "enddate": 'Epoch(Unix) timestamp in milliseconds',
1658
1677
  "rowId": 'string with max limit 3 characters,
1659
1678
  "description": "string",
1679
+ "ext_data": {}, // optional
1660
1680
  "model": "STRICT",
1661
1681
  "owner": {
1662
1682
  "userid": "string" //Mandatory if model is 'STRICT'
@@ -51,9 +51,18 @@ function invitations() {
51
51
  context: 'string', // required
52
52
  created: 'string', // required
53
53
  space_title: 'string',
54
- class_enrollment: { classid: 'string },
54
+ class_enrollment: {
55
+ classid: 'string', // required. Correlated with context
56
+ class_role: 'string', // optional
57
+ inviter_email: 'string' // optional
58
+ },
55
59
  invitation_data: [
56
60
  {
61
+ class_enrollment : { // optional, will override the outer context
62
+ classid: 'string' // required. Correlated with context
63
+ class_role: 'string', // optional
64
+ inviter_email: 'string' // optional
65
+ },
57
66
  email: 'string', // required
58
67
  dls_account_status: 'string',
59
68
  ext_account_status: 'string',
@@ -61,6 +70,7 @@ function invitations() {
61
70
  ext_user_id: 'string',
62
71
  first_name: 'string', // required
63
72
  last_name: 'string', // required
73
+ ext_data: {},
64
74
  rowId: 'string', // required
65
75
  role: 'string' /// required
66
76
  },...
@@ -57,7 +57,8 @@ function spaces(accountId) {
57
57
  getExtProduct: getExtProduct.bind(this),
58
58
  getSpaceDetails: getSpaceDetails.bind(this),
59
59
  updateUserInformation: updateUserInformation.bind(this),
60
- getInvitationsByEmail: getInvitationsByEmail.bind(this)
60
+ getInvitationsByEmail: getInvitationsByEmail.bind(this),
61
+ updateInstituteTitle: updateInstituteTitle.bind(this)
61
62
  };
62
63
  }
63
64
 
@@ -512,6 +513,7 @@ function provisionBulkSpaces(options) {
512
513
  * "ext_class_meta" :
513
514
  * {
514
515
  * "description": "string",
516
+ * "ext_data": {},
515
517
  * "title": "string", // mandatory
516
518
  * "startdate": <epoch>, // mandatory
517
519
  * "enddate": <epoch> // mandatory
@@ -985,3 +987,49 @@ function getInvitationsByEmail(options) {
985
987
  }
986
988
  return dfd.promise;
987
989
  }
990
+
991
+ /**
992
+ * This API is used to update an institute's space title
993
+ * options = {
994
+ * space_code: "", // Mandatory, space code of institute whose title is to be updated
995
+ * body : {
996
+ * ext_actor_id: "", // Mandatory
997
+ * data: {
998
+ * space_title: ""
999
+ * }
1000
+ * }
1001
+ * }
1002
+ */
1003
+ function updateInstituteTitle(options){
1004
+ var self = this;
1005
+ // Initializing promise
1006
+ var dfd = q.defer();
1007
+ var err = {};
1008
+ if (options && options.space_code && options.body && options.body.ext_actor_id ) {
1009
+ // Passed all validations, Contruct API url
1010
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.updateInstituteTitle;
1011
+ url = helpers.api.constructAPIUrl(url,
1012
+ { accountId: self.accountId, instituteSpaceCode: options.space_code });
1013
+
1014
+ // Setup request with URL and Params
1015
+ var requestAPI = request.put(url)
1016
+ .set('Content-Type', 'application/json')
1017
+ .set('Accept', 'application/json')
1018
+ .send(options.body);
1019
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
1020
+
1021
+ requestAPI.end(function (error, response) {
1022
+ if (error) {
1023
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
1024
+ dfd.reject(err);
1025
+ }
1026
+ else { dfd.resolve(response.body); }
1027
+ });
1028
+ }
1029
+ else {
1030
+ err.message = err.description = 'space_code or ext_actor_id not found in request options.';
1031
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
1032
+ dfd.reject(err);
1033
+ }
1034
+ return dfd.promise;
1035
+ }
@@ -38,10 +38,12 @@ module.exports = xapi;
38
38
  /*********************************
39
39
  * Public Function definitions
40
40
  **********************************/
41
- function xapi() {
41
+ function xapi(accountId) {
42
+ this.accountId = accountId;
42
43
  return {
43
44
  postStatement: postStatements.bind(this),
44
- postExternalStatements: postExternalStatements.bind(this)
45
+ postExternalStatements: postExternalStatements.bind(this),
46
+ resetUserProductProgress: resetUserProductProgress.bind(this)
45
47
  };
46
48
  }
47
49
 
@@ -230,3 +232,44 @@ function postExternalStatements(options) {
230
232
  });
231
233
  return dfd.promise;
232
234
  }
235
+
236
+ /*options = {
237
+ userid: 'string',
238
+ productcode: 'string',
239
+ actorid: 'string'
240
+ }*/
241
+ function resetUserProductProgress(options) {
242
+ var self = this;
243
+ // Initializing promise
244
+ var dfd = q.defer();
245
+ var err = {};
246
+ if(options && options.userid && options.productcode && options.actorid) {
247
+
248
+ // Passed all validations, Contruct API url
249
+ var url = self.config.DEFAULT_HOSTS.XAPI + self.config.XAPI_API_URLS.resetUserProductProgress;
250
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
251
+
252
+ // Setup request with URL and Params
253
+ var requestAPI = request.delete(url)
254
+ .set('Content-Type', 'application/json')
255
+ .set('Accept', 'application/json')
256
+ .send(options);
257
+
258
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
259
+
260
+ requestAPI.end(function(error, response) {
261
+ if(error) {
262
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
263
+ dfd.reject(err);
264
+ }
265
+ else { dfd.resolve(response.body); }
266
+ });
267
+ }
268
+ else {
269
+ err.message = err.description = 'userid, productcode or actorid not found in request options.';
270
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
271
+ dfd.reject(err);
272
+ }
273
+
274
+ return dfd.promise;
275
+ }
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.16.0",
4
+ "version": "2.19.1",
5
5
  "author": {
6
6
  "name": "Compro Technologies Private Limited",
7
7
  "url": "http://www.comprotechnologies.com/"
@@ -20,7 +20,8 @@
20
20
  "tincanjs": "^0.50.0",
21
21
  "underscore": "1.8.3",
22
22
  "validate.js": "^0.9.0",
23
- "pubnub": "4.24.2"
23
+ "pubnub": "4.24.2",
24
+ "agentkeepalive": "4.2.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "grunt": "^0.4.5",