comprodls-sdk 2.11.7 → 2.12.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.
Files changed (48) hide show
  1. package/.eslintrc +28 -28
  2. package/.npmignore +5 -0
  3. package/README.md +371 -371
  4. package/dist/comprodls-sdk.js +11493 -11301
  5. package/dist/comprodls-sdk.min.js +18 -18
  6. package/grunt/publish.js +148 -148
  7. package/lib/comprodls.js +146 -146
  8. package/lib/config/index.js +337 -336
  9. package/lib/helpers/index.js +29 -29
  10. package/lib/helpers/lib/api/converter.js +119 -119
  11. package/lib/helpers/lib/api/index.js +120 -120
  12. package/lib/helpers/lib/api/validations.js +72 -72
  13. package/lib/helpers/lib/errors.js +129 -129
  14. package/lib/helpers/lib/utils.js +23 -23
  15. package/lib/helpers/lib/validator.js +100 -100
  16. package/lib/open_access/index.js +121 -121
  17. package/lib/services/activity/activity.js +209 -209
  18. package/lib/services/activity/attempt.js +431 -431
  19. package/lib/services/activity/index.js +28 -28
  20. package/lib/services/analytics/index.js +1555 -1555
  21. package/lib/services/attempts/index.js +342 -342
  22. package/lib/services/auth/classProduct.js +37 -37
  23. package/lib/services/auth/index.js +2541 -2535
  24. package/lib/services/collab/index.js +468 -468
  25. package/lib/services/drive/index.js +144 -144
  26. package/lib/services/integrations/index.js +279 -116
  27. package/lib/services/invitations/index.js +313 -313
  28. package/lib/services/lrs/index.js +459 -459
  29. package/lib/services/product/index.js +267 -267
  30. package/lib/services/pub/index.js +407 -407
  31. package/lib/services/push/index.js +187 -187
  32. package/lib/services/push/pubnubClientWrapper.js +557 -557
  33. package/lib/services/push/sessionStorage.js +64 -64
  34. package/lib/services/pushX/index.js +190 -190
  35. package/lib/services/pushX/pubnubClientWrapper.js +211 -211
  36. package/lib/services/sisevents/index.js +113 -113
  37. package/lib/services/spaces/index.js +976 -929
  38. package/lib/services/superuser/index.js +175 -175
  39. package/lib/services/workflows/index.js +464 -464
  40. package/lib/services/xapi/index.js +232 -232
  41. package/lib/token/index.js +114 -114
  42. package/lib/token/validations.js +88 -88
  43. package/package-lock.json +5095 -0
  44. package/package.json +1 -1
  45. package/test.js +50 -50
  46. package/.vscode/launch.json +0 -23
  47. package/npm-debug.log.189866131 +0 -0
  48. package/npm-debug.log.712840116 +0 -26
@@ -1,407 +1,407 @@
1
- /*************************************************************************
2
- *
3
- * COMPRO CONFIDENTIAL
4
- * __________________
5
- *
6
- * [2015] - [2020] Compro Technologies Private Limited
7
- * All Rights Reserved.
8
- *
9
- * NOTICE: All information contained herein is, and remains
10
- * the property of Compro Technologies Private Limited. The
11
- * intellectual and technical concepts contained herein are
12
- * proprietary to Compro Technologies Private Limited and may
13
- * be covered by U.S. and Foreign Patents, patents in process,
14
- * and are protected by trade secret or copyright law.
15
- *
16
- * Dissemination of this information or reproduction of this material
17
- * is strictly forbidden unless prior written permission is obtained
18
- * from Compro Technologies Pvt. Ltd..
19
- ***************************************************************************/
20
- /***********************************************************
21
- * comproDLS SDK Pub Adaptor
22
- * Functions for calling Pub.
23
- ************************************************************/
24
-
25
- var request = require('superagent');
26
- var q = require('q');
27
-
28
- var helpers = require('../../helpers');
29
- var DLSError = helpers.errors.DLSError;
30
-
31
- /*********************************
32
- * Setting Up Module Entry Point
33
- **********************************/
34
- module.exports = pub;
35
-
36
- function pub() {
37
- 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
- };
46
- }
47
-
48
- /*********************************
49
- * Public Function definitions
50
- **********************************/
51
-
52
- /**
53
- * {
54
- "source": {
55
- "stage": "1" //["1", "2"]
56
- },
57
- "target": {
58
- "org": <target_org> //optional, mandatory for sourceStage-1 + targetStage-2
59
- "stage": "2" //["2", "final"]
60
- },
61
- "externalrefid": <externalID>,
62
- "productcode": "string"
63
- }
64
- */
65
- function promoteProduct(options) {
66
- var self = this;
67
-
68
- //Initializing promise
69
- var dfd = q.defer();
70
-
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
- //Contruct parameters
77
- var params = {
78
- source: {},
79
- target: {}
80
- };
81
- if (options) {
82
- if (options.source && options.source.stage) {
83
- params.source.stage = options.source.stage;
84
- }
85
- if (options.target) {
86
- if(options.target.org) {
87
- params.target.org = options.target.org;
88
- }
89
- if(options.target.stage) {
90
- params.target.stage = options.target.stage;
91
- }
92
- }
93
- if(options.externalrefid) {
94
- params.externalrefid = options.externalrefid;
95
- }
96
- }
97
-
98
- //Setup request with URL and Post data
99
- var requestAPI = request.post(url).send(params);
100
-
101
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
102
- requestAPI.end(function (err, response) {
103
- if (err) {
104
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
105
- dfd.reject(err);
106
- } else {
107
- dfd.resolve(response);
108
- }
109
- });
110
- return dfd.promise;
111
- }
112
-
113
- //options = {
114
- // targetorg: 'dev',
115
- // repositorytype: 'github', //mandatory
116
- // productcode: 'Product code', //mandatory
117
- // title: 'Product title', //mandatory
118
- // producttype: 'Product type', //mandatory e.g., etextbook, imgbook, courseware.
119
- // bundle-codes: ['bundle-code of the bundle'] //optional: Product register request, related to a Bundle, currently only one buldle-code in Array
120
- // externalrefid: <externalID>
121
- //
122
- // /* Note: Register via github is no more supported from v2.5. */
123
- // github: {
124
- // repository: 'Github repository',
125
- // token: 'Github Auth token'
126
- // }
127
- //}
128
- function registerProduct(options) {
129
- var self = this;
130
-
131
- //Initializing promise
132
- var dfd = q.defer();
133
-
134
- //Construct API url
135
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.registerProductAPI;
136
- url = helpers.api.constructAPIUrl(url, { "orgId" : self.orgId });
137
-
138
- //Contruct parameters
139
- var params = {};
140
- if(options) {
141
- if(options.targetorg) {
142
- params.targetorgid = options.targetorg;
143
- }
144
- if(options.repositorytype) {
145
- params.repositorytype = options.repositorytype;
146
- }
147
- if(options.producttitle) {
148
- params.producttitle = options.producttitle;
149
- }
150
- if(options.producttype) {
151
- params.producttype = options.producttype;
152
- }
153
- if(options.productcode) {
154
- params.productcode = options.productcode;
155
- }
156
- if(options.github) {
157
- params.github = options.github;
158
- }
159
- if(options.s3) {
160
- params.s3 = options.s3;
161
- }
162
- if(options.externalrefid) {
163
- params.externalrefid = options.externalrefid;
164
- }
165
- if(options['bundle-codes']) {
166
- params['bundle-codes'] = options['bundle-codes'];
167
- }
168
- }
169
-
170
- //Setup request with URL and Post data
171
- var requestAPI = request.post(url).send(params);
172
-
173
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
174
- requestAPI.end(function(err, response) {
175
- if (err) {
176
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
177
- dfd.reject(err);
178
- } else {
179
- dfd.resolve(response);
180
- }
181
- });
182
- return dfd.promise;
183
- }
184
-
185
- //options = {
186
- // productcode: "string",
187
- // branchref: 'Github branch name or s3 folder path', //mandatory, ingestion via Github no more supported from v2.5.
188
- // "externalrefid": <externalID>,
189
- // "bundle-codes": ['bundle-code of the bundle'] //optional: Product register request, related to a Bundle
190
- //}
191
- function ingestProduct(options) {
192
- var self = this;
193
-
194
- //Initializing promise
195
- var dfd = q.defer();
196
-
197
- var productCode;
198
- if(options && options.productcode) {
199
- productCode = options.productcode;
200
- }
201
-
202
- //Construct API url
203
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.ingestByCodeAPI;
204
- url = helpers.api.constructAPIUrl(url, {
205
- "orgId" : self.orgId,
206
- "productcode" : productCode
207
- });
208
- //Contruct parameters
209
- var params = {};
210
- if(options) {
211
- if(options.branchref) {
212
- params.branchref = options.branchref;
213
- }
214
- if(options.externalrefid) {
215
- params.externalrefid = options.externalrefid;
216
- }
217
- if(options['bundle-codes']) {
218
- params['bundle-codes'] = options['bundle-codes'];
219
- }
220
- }
221
-
222
- //Setup request with URL and Post data
223
- var requestAPI = request.post(url).send(params);
224
-
225
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
226
- requestAPI.end(function(err, response) {
227
- if (err) {
228
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
229
- dfd.reject(err);
230
- } else {
231
- dfd.resolve(response);
232
- }
233
- });
234
- return dfd.promise;
235
- }
236
-
237
- // options = {
238
- // stage: "", //stage number or version
239
- // "bundle-code": "", //bundle identifier
240
- // body: {
241
- // title: "", //bundle title
242
- // products: [] //products array of objects containing following keys:
243
- //mandatory fields: ext-product, dls-product, meta, activation, analytics, classes,
244
- //optional fields: groups, segment, results-display, assignability, learning-path, activity
245
- // }
246
- // }
247
- function createBundle(options) {
248
- var self = this;
249
- //Initializing promise
250
- var dfd = q.defer();
251
- var err;
252
- //Validations
253
- if(options && options.stage && options['bundle-code'] && options.body && options.body.title &&
254
- options.body.products)
255
- {
256
- //Passed all validations, Construct API url
257
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.createBundle;
258
- url = helpers.api.constructAPIUrl(url, { orgid: self.orgId, stage: options.stage });
259
-
260
- //Contruct parameters
261
- options.body['bundle-code'] = options['bundle-code'];
262
- //Setup request with URL and Post data
263
- var requestAPI = request.post(url).send(options.body);
264
-
265
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
266
-
267
- requestAPI.end(function (err, response) {
268
- if(err) {
269
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
270
- dfd.reject(err);
271
- } else {
272
- dfd.resolve(response.body);
273
- }
274
- });
275
- }
276
- else {
277
- err = {};
278
- err.message = err.description = 'Required parameter stage or bundle-code or title or ' +
279
- 'products not found in request options';
280
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
281
- dfd.reject(err);
282
- }
283
- return dfd.promise;
284
- }
285
-
286
- // options = {
287
- // stage: "", //stage number or version
288
- // "bundle-code": "", //bundle identifier
289
- // body: {
290
- // title: "", //bundle title (optional)
291
- // products: [] //products array of objects containing following keys:
292
- //mandatory fields: ext-product, dls-product, meta, activation, analytics, classes,
293
- //optional fields: groups, segment, results-display, assignability, learning-path, activity
294
- // }
295
- // }
296
- function updateBundle(options) {
297
- var self = this;
298
-
299
- //Initializing promise
300
- var dfd = q.defer();
301
- var err;
302
-
303
- //Validations
304
- if(options && options.stage && options['bundle-code'] && options.body && options.body.products) {
305
- //Passed all validations, Construct API url
306
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.updateBundle;
307
- url = helpers.api.constructAPIUrl(url, {
308
- orgid: self.orgId, stage: options.stage, bundleCode: options['bundle-code']
309
- });
310
-
311
- //Setup request with URL and Post data
312
- var requestAPI = request.put(url).send(options.body);
313
-
314
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
315
- requestAPI.end(function (err, response) {
316
- if(err) {
317
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
318
- dfd.reject(err);
319
- } else {
320
- dfd.resolve(response.body);
321
- }
322
- });
323
- }
324
- else {
325
- err = {};
326
- err.message = err.description = 'Required parameter stage or bundle-code or ' +
327
- 'products not found in request options';
328
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
329
- dfd.reject(err);
330
- }
331
- return dfd.promise;
332
- }
333
-
334
- // options= {
335
- // stage: "", //stage number or version
336
- // }
337
-
338
- function getAllBundles(options) {
339
- var self = this;
340
- //Initializing promise
341
- var dfd = q.defer();
342
-
343
- //Construct API url
344
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.getAllBundles;
345
-
346
- url = helpers.api.constructAPIUrl(url, { orgid: self.orgId, });
347
- //Contruct parameters
348
- var params = {};
349
- if(options && options.stage) { params.stage = options.stage; }
350
-
351
- //Setup request with URL and Post data
352
- var requestAPI = request.get(url).query(params);
353
-
354
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
355
- requestAPI.end(function (err, response) {
356
- if(err) {
357
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
358
- dfd.reject(err);
359
- } else {
360
- dfd.resolve(response.body);
361
- }
362
- });
363
- return dfd.promise;
364
- }
365
-
366
- // options = {
367
- // 'bundle-code': "", //bundle identifier
368
- // stage: "", //stage number/version
369
- // }
370
- function getSingleBundle(options) {
371
- var self = this;
372
- var dfd = q.defer();
373
-
374
- //Validations
375
- var err;
376
- if(options && options['bundle-code']) {
377
-
378
- //Passed all validations, Construct API url
379
- var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.getSingleBundle;
380
-
381
- url = helpers.api.constructAPIUrl(url, { orgid: self.orgId, bundleCode: options['bundle-code'] });
382
- //Contruct parameters
383
- var params = {};
384
- if(options && options.stage) { params.stage = options.stage; }
385
- //Setup request with URL and Post data
386
-
387
- var requestAPI = request.get(url).query(params);
388
-
389
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
390
- requestAPI.end(function (err, response) {
391
- if(err) {
392
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
393
- dfd.reject(err);
394
- } else {
395
- dfd.resolve(response.body);
396
- }
397
- });
398
- }
399
- else {
400
- err = {};
401
- err.message = err.description = 'Required parameter bundle-code not found in request options';
402
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
403
- dfd.reject(err);
404
- }
405
-
406
- return dfd.promise;
407
- }
1
+ /*************************************************************************
2
+ *
3
+ * COMPRO CONFIDENTIAL
4
+ * __________________
5
+ *
6
+ * [2015] - [2020] Compro Technologies Private Limited
7
+ * All Rights Reserved.
8
+ *
9
+ * NOTICE: All information contained herein is, and remains
10
+ * the property of Compro Technologies Private Limited. The
11
+ * intellectual and technical concepts contained herein are
12
+ * proprietary to Compro Technologies Private Limited and may
13
+ * be covered by U.S. and Foreign Patents, patents in process,
14
+ * and are protected by trade secret or copyright law.
15
+ *
16
+ * Dissemination of this information or reproduction of this material
17
+ * is strictly forbidden unless prior written permission is obtained
18
+ * from Compro Technologies Pvt. Ltd..
19
+ ***************************************************************************/
20
+ /***********************************************************
21
+ * comproDLS SDK Pub Adaptor
22
+ * Functions for calling Pub.
23
+ ************************************************************/
24
+
25
+ var request = require('superagent');
26
+ var q = require('q');
27
+
28
+ var helpers = require('../../helpers');
29
+ var DLSError = helpers.errors.DLSError;
30
+
31
+ /*********************************
32
+ * Setting Up Module Entry Point
33
+ **********************************/
34
+ module.exports = pub;
35
+
36
+ function pub() {
37
+ 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
+ };
46
+ }
47
+
48
+ /*********************************
49
+ * Public Function definitions
50
+ **********************************/
51
+
52
+ /**
53
+ * {
54
+ "source": {
55
+ "stage": "1" //["1", "2"]
56
+ },
57
+ "target": {
58
+ "org": <target_org> //optional, mandatory for sourceStage-1 + targetStage-2
59
+ "stage": "2" //["2", "final"]
60
+ },
61
+ "externalrefid": <externalID>,
62
+ "productcode": "string"
63
+ }
64
+ */
65
+ function promoteProduct(options) {
66
+ var self = this;
67
+
68
+ //Initializing promise
69
+ var dfd = q.defer();
70
+
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
+ //Contruct parameters
77
+ var params = {
78
+ source: {},
79
+ target: {}
80
+ };
81
+ if (options) {
82
+ if (options.source && options.source.stage) {
83
+ params.source.stage = options.source.stage;
84
+ }
85
+ if (options.target) {
86
+ if(options.target.org) {
87
+ params.target.org = options.target.org;
88
+ }
89
+ if(options.target.stage) {
90
+ params.target.stage = options.target.stage;
91
+ }
92
+ }
93
+ if(options.externalrefid) {
94
+ params.externalrefid = options.externalrefid;
95
+ }
96
+ }
97
+
98
+ //Setup request with URL and Post data
99
+ var requestAPI = request.post(url).send(params);
100
+
101
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
102
+ requestAPI.end(function (err, response) {
103
+ if (err) {
104
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
105
+ dfd.reject(err);
106
+ } else {
107
+ dfd.resolve(response);
108
+ }
109
+ });
110
+ return dfd.promise;
111
+ }
112
+
113
+ //options = {
114
+ // targetorg: 'dev',
115
+ // repositorytype: 'github', //mandatory
116
+ // productcode: 'Product code', //mandatory
117
+ // title: 'Product title', //mandatory
118
+ // producttype: 'Product type', //mandatory e.g., etextbook, imgbook, courseware.
119
+ // bundle-codes: ['bundle-code of the bundle'] //optional: Product register request, related to a Bundle, currently only one buldle-code in Array
120
+ // externalrefid: <externalID>
121
+ //
122
+ // /* Note: Register via github is no more supported from v2.5. */
123
+ // github: {
124
+ // repository: 'Github repository',
125
+ // token: 'Github Auth token'
126
+ // }
127
+ //}
128
+ function registerProduct(options) {
129
+ var self = this;
130
+
131
+ //Initializing promise
132
+ var dfd = q.defer();
133
+
134
+ //Construct API url
135
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.registerProductAPI;
136
+ url = helpers.api.constructAPIUrl(url, { "orgId" : self.orgId });
137
+
138
+ //Contruct parameters
139
+ var params = {};
140
+ if(options) {
141
+ if(options.targetorg) {
142
+ params.targetorgid = options.targetorg;
143
+ }
144
+ if(options.repositorytype) {
145
+ params.repositorytype = options.repositorytype;
146
+ }
147
+ if(options.producttitle) {
148
+ params.producttitle = options.producttitle;
149
+ }
150
+ if(options.producttype) {
151
+ params.producttype = options.producttype;
152
+ }
153
+ if(options.productcode) {
154
+ params.productcode = options.productcode;
155
+ }
156
+ if(options.github) {
157
+ params.github = options.github;
158
+ }
159
+ if(options.s3) {
160
+ params.s3 = options.s3;
161
+ }
162
+ if(options.externalrefid) {
163
+ params.externalrefid = options.externalrefid;
164
+ }
165
+ if(options['bundle-codes']) {
166
+ params['bundle-codes'] = options['bundle-codes'];
167
+ }
168
+ }
169
+
170
+ //Setup request with URL and Post data
171
+ var requestAPI = request.post(url).send(params);
172
+
173
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
174
+ requestAPI.end(function(err, response) {
175
+ if (err) {
176
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
177
+ dfd.reject(err);
178
+ } else {
179
+ dfd.resolve(response);
180
+ }
181
+ });
182
+ return dfd.promise;
183
+ }
184
+
185
+ //options = {
186
+ // productcode: "string",
187
+ // branchref: 'Github branch name or s3 folder path', //mandatory, ingestion via Github no more supported from v2.5.
188
+ // "externalrefid": <externalID>,
189
+ // "bundle-codes": ['bundle-code of the bundle'] //optional: Product register request, related to a Bundle
190
+ //}
191
+ function ingestProduct(options) {
192
+ var self = this;
193
+
194
+ //Initializing promise
195
+ var dfd = q.defer();
196
+
197
+ var productCode;
198
+ if(options && options.productcode) {
199
+ productCode = options.productcode;
200
+ }
201
+
202
+ //Construct API url
203
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.ingestByCodeAPI;
204
+ url = helpers.api.constructAPIUrl(url, {
205
+ "orgId" : self.orgId,
206
+ "productcode" : productCode
207
+ });
208
+ //Contruct parameters
209
+ var params = {};
210
+ if(options) {
211
+ if(options.branchref) {
212
+ params.branchref = options.branchref;
213
+ }
214
+ if(options.externalrefid) {
215
+ params.externalrefid = options.externalrefid;
216
+ }
217
+ if(options['bundle-codes']) {
218
+ params['bundle-codes'] = options['bundle-codes'];
219
+ }
220
+ }
221
+
222
+ //Setup request with URL and Post data
223
+ var requestAPI = request.post(url).send(params);
224
+
225
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
226
+ requestAPI.end(function(err, response) {
227
+ if (err) {
228
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
229
+ dfd.reject(err);
230
+ } else {
231
+ dfd.resolve(response);
232
+ }
233
+ });
234
+ return dfd.promise;
235
+ }
236
+
237
+ // options = {
238
+ // stage: "", //stage number or version
239
+ // "bundle-code": "", //bundle identifier
240
+ // body: {
241
+ // title: "", //bundle title
242
+ // products: [] //products array of objects containing following keys:
243
+ //mandatory fields: ext-product, dls-product, meta, activation, analytics, classes,
244
+ //optional fields: groups, segment, results-display, assignability, learning-path, activity
245
+ // }
246
+ // }
247
+ function createBundle(options) {
248
+ var self = this;
249
+ //Initializing promise
250
+ var dfd = q.defer();
251
+ var err;
252
+ //Validations
253
+ if(options && options.stage && options['bundle-code'] && options.body && options.body.title &&
254
+ options.body.products)
255
+ {
256
+ //Passed all validations, Construct API url
257
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.createBundle;
258
+ url = helpers.api.constructAPIUrl(url, { orgid: self.orgId, stage: options.stage });
259
+
260
+ //Contruct parameters
261
+ options.body['bundle-code'] = options['bundle-code'];
262
+ //Setup request with URL and Post data
263
+ var requestAPI = request.post(url).send(options.body);
264
+
265
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
266
+
267
+ requestAPI.end(function (err, response) {
268
+ if(err) {
269
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
270
+ dfd.reject(err);
271
+ } else {
272
+ dfd.resolve(response.body);
273
+ }
274
+ });
275
+ }
276
+ else {
277
+ err = {};
278
+ err.message = err.description = 'Required parameter stage or bundle-code or title or ' +
279
+ 'products not found in request options';
280
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
281
+ dfd.reject(err);
282
+ }
283
+ return dfd.promise;
284
+ }
285
+
286
+ // options = {
287
+ // stage: "", //stage number or version
288
+ // "bundle-code": "", //bundle identifier
289
+ // body: {
290
+ // title: "", //bundle title (optional)
291
+ // products: [] //products array of objects containing following keys:
292
+ //mandatory fields: ext-product, dls-product, meta, activation, analytics, classes,
293
+ //optional fields: groups, segment, results-display, assignability, learning-path, activity
294
+ // }
295
+ // }
296
+ function updateBundle(options) {
297
+ var self = this;
298
+
299
+ //Initializing promise
300
+ var dfd = q.defer();
301
+ var err;
302
+
303
+ //Validations
304
+ if(options && options.stage && options['bundle-code'] && options.body && options.body.products) {
305
+ //Passed all validations, Construct API url
306
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.updateBundle;
307
+ url = helpers.api.constructAPIUrl(url, {
308
+ orgid: self.orgId, stage: options.stage, bundleCode: options['bundle-code']
309
+ });
310
+
311
+ //Setup request with URL and Post data
312
+ var requestAPI = request.put(url).send(options.body);
313
+
314
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
315
+ requestAPI.end(function (err, response) {
316
+ if(err) {
317
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
318
+ dfd.reject(err);
319
+ } else {
320
+ dfd.resolve(response.body);
321
+ }
322
+ });
323
+ }
324
+ else {
325
+ err = {};
326
+ err.message = err.description = 'Required parameter stage or bundle-code or ' +
327
+ 'products not found in request options';
328
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
329
+ dfd.reject(err);
330
+ }
331
+ return dfd.promise;
332
+ }
333
+
334
+ // options= {
335
+ // stage: "", //stage number or version
336
+ // }
337
+
338
+ function getAllBundles(options) {
339
+ var self = this;
340
+ //Initializing promise
341
+ var dfd = q.defer();
342
+
343
+ //Construct API url
344
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.getAllBundles;
345
+
346
+ url = helpers.api.constructAPIUrl(url, { orgid: self.orgId, });
347
+ //Contruct parameters
348
+ var params = {};
349
+ if(options && options.stage) { params.stage = options.stage; }
350
+
351
+ //Setup request with URL and Post data
352
+ var requestAPI = request.get(url).query(params);
353
+
354
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
355
+ requestAPI.end(function (err, response) {
356
+ if(err) {
357
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
358
+ dfd.reject(err);
359
+ } else {
360
+ dfd.resolve(response.body);
361
+ }
362
+ });
363
+ return dfd.promise;
364
+ }
365
+
366
+ // options = {
367
+ // 'bundle-code': "", //bundle identifier
368
+ // stage: "", //stage number/version
369
+ // }
370
+ function getSingleBundle(options) {
371
+ var self = this;
372
+ var dfd = q.defer();
373
+
374
+ //Validations
375
+ var err;
376
+ if(options && options['bundle-code']) {
377
+
378
+ //Passed all validations, Construct API url
379
+ var url = self.config.DEFAULT_HOSTS['PUB'] + self.config.PUB_API_URLS.getSingleBundle;
380
+
381
+ url = helpers.api.constructAPIUrl(url, { orgid: self.orgId, bundleCode: options['bundle-code'] });
382
+ //Contruct parameters
383
+ var params = {};
384
+ if(options && options.stage) { params.stage = options.stage; }
385
+ //Setup request with URL and Post data
386
+
387
+ var requestAPI = request.get(url).query(params);
388
+
389
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
390
+ requestAPI.end(function (err, response) {
391
+ if(err) {
392
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
393
+ dfd.reject(err);
394
+ } else {
395
+ dfd.resolve(response.body);
396
+ }
397
+ });
398
+ }
399
+ else {
400
+ err = {};
401
+ err.message = err.description = 'Required parameter bundle-code not found in request options';
402
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
403
+ dfd.reject(err);
404
+ }
405
+
406
+ return dfd.promise;
407
+ }