comprodls-sdk 2.90.3-development → 2.92.0-thor

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.
Files changed (42) hide show
  1. package/README.md +1 -137
  2. package/dist/comprodls-sdk.js +2834 -6201
  3. package/dist/comprodls-sdk.min.js +1 -1
  4. package/lib/comprodls.js +39 -57
  5. package/lib/config/index.js +173 -198
  6. package/lib/helpers/index.js +3 -2
  7. package/lib/helpers/lib/api/converter.js +1 -2
  8. package/lib/helpers/lib/api/index.js +19 -94
  9. package/lib/helpers/lib/errors.js +75 -80
  10. package/lib/helpers/lib/requestLayer.js +154 -0
  11. package/lib/helpers/lib/validator.js +65 -52
  12. package/lib/open_access/index.js +48 -53
  13. package/lib/services/analytics/index.js +286 -1014
  14. package/lib/services/attempts/index.js +38 -88
  15. package/lib/services/auth/index.js +324 -806
  16. package/lib/services/authextn/index.js +85 -247
  17. package/lib/services/datasyncmanager/index.js +10 -45
  18. package/lib/services/drive/index.js +20 -83
  19. package/lib/services/integrations/index.js +51 -126
  20. package/lib/services/invitations/index.js +20 -61
  21. package/lib/services/product/index.js +82 -85
  22. package/lib/services/pub/index.js +167 -235
  23. package/lib/services/pushX/index.js +195 -142
  24. package/lib/services/pushX/pubnubClientWrapper.js +399 -172
  25. package/lib/services/rules/index.js +14 -67
  26. package/lib/services/spaces/index.js +141 -318
  27. package/lib/services/spacesextn/index.js +44 -20
  28. package/lib/services/superuser/index.js +21 -36
  29. package/lib/services/taxonomy/index.js +27 -57
  30. package/lib/services/workflows/index.js +38 -97
  31. package/lib/services/xapi/index.js +7 -168
  32. package/lib/token/index.js +73 -67
  33. package/lib/token/validations.js +45 -48
  34. package/package.json +2 -3
  35. package/lib/helpers/lib/api/validations.js +0 -73
  36. package/lib/helpers/lib/utils.js +0 -24
  37. package/lib/services/activity/activity.js +0 -209
  38. package/lib/services/activity/attempt.js +0 -431
  39. package/lib/services/activity/index.js +0 -28
  40. package/lib/services/auth/classProduct.js +0 -37
  41. package/lib/services/collab/index.js +0 -468
  42. package/test.js +0 -38
@@ -17,6 +17,7 @@
17
17
  * is strictly forbidden unless prior written permission is obtained
18
18
  * from Compro Technologies Pvt. Ltd..
19
19
  ***************************************************************************/
20
+
20
21
  /***********************************************************
21
22
  * comproDLS SDK Pub Adaptor
22
23
  * Functions for calling Pub.
@@ -24,28 +25,31 @@
24
25
 
25
26
  var request = require('superagent');
26
27
  var q = require('q');
28
+ var Agent = require('agentkeepalive');
27
29
 
28
30
  var helpers = require('../../helpers');
29
31
  var DLSError = helpers.errors.DLSError;
30
32
 
31
- /*********************************
32
- * Setting Up Module Entry Point
33
- **********************************/
33
+ var keepaliveAgent = new Agent({
34
+ timeout: 60000,
35
+ freeSocketTimeout: 30000
36
+ });
37
+
34
38
  module.exports = pub;
35
39
 
36
40
  function pub() {
37
41
  return {
38
- "promoteProduct": promoteProduct.bind(this),
39
- "registerProduct": registerProduct.bind(this),
40
- "ingestProduct": ingestProduct.bind(this),
41
- "createBundle": createBundle.bind(this),
42
- "updateBundle": updateBundle.bind(this),
43
- "getAllBundles": getAllBundles.bind(this),
44
- "getSingleBundle": getSingleBundle.bind(this),
45
- "createProductFamily": createProductFamily.bind(this),
46
- "updateProductFamily": updateProductFamily.bind(this),
47
- "getSingleProductFamily": getSingleProductFamily.bind(this),
48
- "getAllProductFamilies": getAllProductFamilies.bind(this)
42
+ promoteProduct: promoteProduct.bind(this),
43
+ registerProduct: registerProduct.bind(this),
44
+ ingestProduct: ingestProduct.bind(this),
45
+ createBundle: createBundle.bind(this),
46
+ updateBundle: updateBundle.bind(this),
47
+ getAllBundles: getAllBundles.bind(this),
48
+ getSingleBundle: getSingleBundle.bind(this),
49
+ createProductFamily: createProductFamily.bind(this),
50
+ updateProductFamily: updateProductFamily.bind(this),
51
+ getSingleProductFamily: getSingleProductFamily.bind(this),
52
+ getAllProductFamilies: getAllProductFamilies.bind(this)
49
53
  };
50
54
  }
51
55
 
@@ -54,200 +58,156 @@ function pub() {
54
58
  **********************************/
55
59
 
56
60
  /**
57
- * {
58
- "source": {
59
- "stage": "1" //["1", "2"]
60
- },
61
- "target": {
62
- "org": <target_org> //optional, mandatory for sourceStage-1 + targetStage-2
63
- "stage": "2" //["2", "final"]
64
- },
65
- "externalrefid": <externalID>,
66
- "productcode": "string"
67
- }
61
+ * Wiki Link for SDK params
62
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#promoteproductparams
68
63
  */
69
64
  function promoteProduct(options) {
70
65
  var self = this;
71
-
72
66
  //Initializing promise
73
67
  var dfd = q.defer();
74
68
 
75
- //Construct API url
76
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.promoteAPI;
77
- url = helpers.api.constructAPIUrl(url, {
78
- "orgId": self.orgId, "productcode": options.productcode
79
- });
80
69
  //Contruct parameters
81
- var params = {
82
- source: {},
83
- target: {}
84
- };
85
- if (options) {
86
- if (options.source && options.source.stage) {
87
- params.source.stage = options.source.stage;
88
- }
70
+ if (options && options.productcode) {
71
+ //Construct API url
72
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.promoteAPI;
73
+ url = helpers.api.constructAPIUrl(url, {
74
+ 'orgId': self.orgId, 'productcode': options.productcode
75
+ });
76
+
77
+ var params = { source: {}, target: {} };
78
+ if (options.ext_user_id) { params.ext_user_id = options.ext_user_id; }
79
+ if (options.source && options.source.stage) { params.source.stage = options.source.stage; }
89
80
  if (options.target) {
90
- if(options.target.org) {
91
- params.target.org = options.target.org;
92
- }
93
- if(options.target.stage) {
94
- params.target.stage = options.target.stage;
95
- }
81
+ if(options.target.org) { params.target.org = options.target.org; }
82
+ if(options.target.stage) { params.target.stage = options.target.stage; }
96
83
  }
97
- if(options.externalrefid) {
98
- params.externalrefid = options.externalrefid;
99
- }
100
- }
84
+ if(options.externalrefid) { params.externalrefid = options.externalrefid; }
101
85
 
102
- //Setup request with URL and Post data
103
- var requestAPI = request.post(url).send(params);
86
+ //Setup request with URL and Post data
87
+ var requestAPI = request.post(url).send(params);
88
+
89
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
90
+ requestAPI
91
+ .agent(keepaliveAgent)
92
+ .end(function (err, response) {
93
+ if (err) {
94
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
95
+ dfd.reject(err);
96
+ } else {
97
+ dfd.resolve(response);
98
+ }
99
+ });
100
+ } else {
101
+ var err = {};
102
+ err.message = err.description = 'Mandatory field \'options\' are not provided '+
103
+ 'in the request options.';
104
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
105
+ dfd.reject(err);
106
+ }
104
107
 
105
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
106
- requestAPI.end(function (err, response) {
107
- if (err) {
108
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
109
- dfd.reject(err);
110
- } else {
111
- dfd.resolve(response);
112
- }
113
- });
114
108
  return dfd.promise;
115
109
  }
116
110
 
117
- //options = {
118
- // targetorg: 'dev',
119
- // repositorytype: 'github', //mandatory
120
- // productcode: 'Product code', //mandatory
121
- // title: 'Product title', //mandatory
122
- // producttype: 'Product type', //mandatory e.g., etextbook, imgbook, courseware.
123
- // bundle-codes: ['bundle-code of the bundle'] //optional: Product register request, related to a Bundle, currently only one buldle-code in Array
124
- // externalrefid: <externalID>
125
- //
126
- // /* Note: Register via github is no more supported from v2.5. */
127
- // github: {
128
- // repository: 'Github repository',
129
- // token: 'Github Auth token'
130
- // }
131
- //}
111
+ /**
112
+ * Wiki Link for SDK params
113
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#registerproductparams
114
+ */
132
115
  function registerProduct(options) {
133
116
  var self = this;
134
-
135
- //Initializing promise
136
117
  var dfd = q.defer();
137
118
 
138
- //Construct API url
139
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.registerProductAPI;
140
- url = helpers.api.constructAPIUrl(url, { "orgId" : self.orgId });
141
-
142
- //Contruct parameters
143
- var params = {};
144
- if(options) {
145
- if(options.targetorg) {
146
- params.targetorgid = options.targetorg;
147
- }
148
- if(options.repositorytype) {
149
- params.repositorytype = options.repositorytype;
150
- }
151
- if(options.producttitle) {
152
- params.producttitle = options.producttitle;
153
- }
154
- if(options.producttype) {
155
- params.producttype = options.producttype;
156
- }
157
- if(options.productcode) {
158
- params.productcode = options.productcode;
159
- }
160
- if(options.github) {
161
- params.github = options.github;
162
- }
163
- if(options.s3) {
164
- params.s3 = options.s3;
165
- }
166
- if(options.externalrefid) {
167
- params.externalrefid = options.externalrefid;
168
- }
169
- if(options['bundle-codes']) {
170
- params['bundle-codes'] = options['bundle-codes'];
171
- }
172
- }
119
+ if (options) {
120
+ //Construct API url
121
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.registerProductAPI;
122
+ url = helpers.api.constructAPIUrl(url, { 'orgId' : self.orgId });
173
123
 
174
- //Setup request with URL and Post data
175
- var requestAPI = request.post(url).send(params);
124
+ var params = {};
125
+ if (options.targetorg) { params.targetorgid = options.targetorg; }
126
+ if (options.repositorytype) { params.repositorytype = options.repositorytype; }
127
+ if (options.producttitle) { params.producttitle = options.producttitle; }
128
+ if (options.producttype) { params.producttype = options.producttype; }
129
+ if (options.productcode) { params.productcode = options.productcode; }
130
+ if (options.s3) { params.s3 = options.s3; }
131
+ if (options.externalrefid) { params.externalrefid = options.externalrefid; }
132
+ if (options['bundle-codes']) { params['bundle-codes'] = options['bundle-codes']; }
133
+
134
+ // Setup request with URL and Post data
135
+ var requestAPI = request.post(url).send(params);
136
+
137
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
138
+ requestAPI
139
+ .agent(keepaliveAgent)
140
+ .end(function(err, response) {
141
+ if (err) {
142
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
143
+ dfd.reject(err);
144
+ } else {
145
+ dfd.resolve(response);
146
+ }
147
+ });
148
+ } else {
149
+ var err = {};
150
+ err.message = err.description = 'Mandatory field \'options\' are not provided '+
151
+ 'in the request options.';
152
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
153
+ dfd.reject(err);
154
+ }
176
155
 
177
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
178
- requestAPI.end(function(err, response) {
179
- if (err) {
180
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
181
- dfd.reject(err);
182
- } else {
183
- dfd.resolve(response);
184
- }
185
- });
186
156
  return dfd.promise;
187
157
  }
188
158
 
189
- //options = {
190
- // productcode: "string",
191
- // branchref: 'Github branch name or s3 folder path', //mandatory, ingestion via Github no more supported from v2.5.
192
- // "externalrefid": <externalID>,
193
- // "bundle-codes": ['bundle-code of the bundle'] //optional: Product register request, related to a Bundle
194
- //}
159
+ /**
160
+ * Wiki Link for SDK params
161
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#ingestproductparams
162
+ */
195
163
  function ingestProduct(options) {
196
164
  var self = this;
197
-
198
165
  //Initializing promise
199
166
  var dfd = q.defer();
200
167
 
201
- var productCode;
202
- if(options && options.productcode) {
203
- productCode = options.productcode;
204
- }
168
+ if (options && options.productcode) {
169
+ //Construct API url
170
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.ingestByCodeAPI;
171
+ url = helpers.api.constructAPIUrl(url, {
172
+ 'orgId' : self.orgId, 'productcode' : options.productcode
173
+ });
205
174
 
206
- //Construct API url
207
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.ingestByCodeAPI;
208
- url = helpers.api.constructAPIUrl(url, {
209
- "orgId" : self.orgId,
210
- "productcode" : productCode
211
- });
212
- //Contruct parameters
213
- var params = {};
214
- if(options) {
215
- if(options.branchref) {
216
- params.branchref = options.branchref;
217
- }
218
- if(options.externalrefid) {
219
- params.externalrefid = options.externalrefid;
220
- }
221
- if(options['bundle-codes']) {
222
- params['bundle-codes'] = options['bundle-codes'];
223
- }
224
- }
175
+ //Contruct parameters
176
+ var params = {};
177
+ if (options.ext_user_id) { params.ext_user_id = options.ext_user_id; }
178
+ if (options.branchref) { params.branchref = options.branchref; }
179
+ if (options.externalrefid) { params.externalrefid = options.externalrefid; }
180
+ if (options['bundle-codes']) { params['bundle-codes'] = options['bundle-codes']; }
225
181
 
226
- //Setup request with URL and Post data
227
- var requestAPI = request.post(url).send(params);
182
+ //Setup request with URL and Post data
183
+ var requestAPI = request.post(url).send(params);
184
+
185
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
186
+ requestAPI
187
+ .agent(keepaliveAgent)
188
+ .end(function(err, response) {
189
+ if (err) {
190
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
191
+ dfd.reject(err);
192
+ } else {
193
+ dfd.resolve(response);
194
+ }
195
+ });
196
+ } else {
197
+ var err = {};
198
+ err.message = err.description = 'Mandatory field \'productcode\' is not provided '+
199
+ 'in the request options.';
200
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
201
+ dfd.reject(err);
202
+ }
228
203
 
229
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
230
- requestAPI.end(function(err, response) {
231
- if (err) {
232
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
233
- dfd.reject(err);
234
- } else {
235
- dfd.resolve(response);
236
- }
237
- });
238
204
  return dfd.promise;
239
205
  }
240
206
 
241
- // options = {
242
- // stage: "", //stage number or version
243
- // "bundle-code": "", //bundle identifier
244
- // body: {
245
- // title: "", //bundle title
246
- // products: [] //products array of objects containing following keys:
247
- //mandatory fields: ext-product, dls-product, meta, activation, analytics, classes,
248
- //optional fields: groups, segment, results-display, assignability, learning-path, activity
249
- // }
250
- // }
207
+ /**
208
+ * Wiki Link for SDK params
209
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#createbundleparams
210
+ */
251
211
  function createBundle(options) {
252
212
  var self = this;
253
213
  //Initializing promise
@@ -287,16 +247,10 @@ function createBundle(options) {
287
247
  return dfd.promise;
288
248
  }
289
249
 
290
- // options = {
291
- // stage: "", //stage number or version
292
- // "bundle-code": "", //bundle identifier
293
- // body: {
294
- // title: "", //bundle title (optional)
295
- // products: [] //products array of objects containing following keys:
296
- //mandatory fields: ext-product, dls-product, meta, activation, analytics, classes,
297
- //optional fields: groups, segment, results-display, assignability, learning-path, activity
298
- // }
299
- // }
250
+ /**
251
+ * Wiki Link for SDK params
252
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#updatebundleparams
253
+ */
300
254
  function updateBundle(options) {
301
255
  var self = this;
302
256
 
@@ -335,10 +289,10 @@ function updateBundle(options) {
335
289
  return dfd.promise;
336
290
  }
337
291
 
338
- // options= {
339
- // stage: "", //stage number or version
340
- // }
341
-
292
+ /**
293
+ * Wiki Link for SDK params
294
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#getallbundlesparams
295
+ */
342
296
  function getAllBundles(options) {
343
297
  var self = this;
344
298
  //Initializing promise
@@ -350,7 +304,14 @@ function getAllBundles(options) {
350
304
  url = helpers.api.constructAPIUrl(url, { orgid: self.orgId, });
351
305
  //Contruct parameters
352
306
  var params = {};
353
- if(options && options.stage) { params.stage = options.stage; }
307
+ if(options) {
308
+ if(options.stage){
309
+ params.stage = options.stage;
310
+ }
311
+ if(options.target_role){
312
+ params.target_role = options.target_role;
313
+ }
314
+ }
354
315
 
355
316
  //Setup request with URL and Post data
356
317
  var requestAPI = request.get(url).query(params);
@@ -367,10 +328,10 @@ function getAllBundles(options) {
367
328
  return dfd.promise;
368
329
  }
369
330
 
370
- // options = {
371
- // 'bundle-code': "", //bundle identifier
372
- // stage: "", //stage number/version
373
- // }
331
+ /**
332
+ * Wiki Link for SDK params
333
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#getsinglebundleparams
334
+ */
374
335
  function getSingleBundle(options) {
375
336
  var self = this;
376
337
  var dfd = q.defer();
@@ -410,23 +371,10 @@ function getSingleBundle(options) {
410
371
  return dfd.promise;
411
372
  }
412
373
 
413
- // options = {
414
- // "stage": <>, // Mandatory
415
- // "body": {
416
- // "family-code": "string", // Mandatory
417
- // "ext_user_id": "string", // Optional
418
- // "assets": { // Optional
419
- // "branchref": "string", // Optional
420
- // "bucket": "string" // Optional
421
- // "source": { // Optional
422
- // "branchref": "string", // Mandatory
423
- // "bucket": "string" // Mandatory
424
- // }
425
- // },
426
- // "externalrefid": "string", // Optional
427
- // "data": {... } // Optional
428
- // }
429
- // }
374
+ /**
375
+ * Wiki Link for SDK params
376
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#createproductfamilyparams
377
+ */
430
378
  function createProductFamily(options) {
431
379
  var self = this;
432
380
  //Initializing promise
@@ -463,23 +411,10 @@ function createProductFamily(options) {
463
411
  return dfd.promise;
464
412
  }
465
413
 
466
- // options = {
467
- // "stage": <>, // Mandatory
468
- // "family-code": <>, // Mandatory
469
- // "body": {
470
- // "ext_user_id": "string", // Optional
471
- // "assets": { // Optional
472
- // "branchref": "string", // Optional
473
- // "bucket": "string" // Optional
474
- // "source": { // Optional
475
- // "branchref": "string", // Mandatory
476
- // "bucket": "string" // Mandatory
477
- // }
478
- // },
479
- // "externalrefid": "string", // Optional
480
- // "data": {... } // Optional
481
- // }
482
- // }
414
+ /**
415
+ * Wiki Link for SDK params
416
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#updateproductfamilyparams
417
+ */
483
418
  function updateProductFamily(options) {
484
419
  var self = this;
485
420
 
@@ -488,7 +423,7 @@ function updateProductFamily(options) {
488
423
  var err;
489
424
 
490
425
  //Validations
491
- if (options && options.stage && options['family-code']) {
426
+ if (options && options.stage && options['family-code']) {
492
427
  //Passed all validations, Construct API url
493
428
  var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.updateProductFamily;
494
429
  url = helpers.api.constructAPIUrl(url, {
@@ -519,10 +454,8 @@ function updateProductFamily(options) {
519
454
  }
520
455
 
521
456
  /**
522
- * options = {
523
- * "family-code": "", //product family identifier, Mandatory
524
- * "stage" : "", //stage number
525
- * }
457
+ * Wiki Link for SDK params
458
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#getsingleproductfamilyparams
526
459
  */
527
460
  function getSingleProductFamily(options) {
528
461
  var self = this;
@@ -565,9 +498,8 @@ function getSingleProductFamily(options) {
565
498
  }
566
499
 
567
500
  /**
568
- * options = {
569
- * "stage": <>, // Optional
570
- * }
501
+ * Wiki Link for SDK params
502
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/07_PUB-Adapter#getallproductfamiliesparams
571
503
  */
572
504
  function getAllProductFamilies(options) {
573
505
  var self = this;