comprodls-sdk 2.123.2-security → 2.123.4-oidc-poc.2

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 (36) hide show
  1. package/.eslintrc +28 -28
  2. package/.github/workflows/npm-publish.yml +76 -0
  3. package/README.md +235 -235
  4. package/dist/comprodls-sdk.js +13543 -13543
  5. package/docs/npm-oidc-publishing-runbook.md +229 -0
  6. package/lib/comprodls.js +132 -132
  7. package/lib/config/index.js +356 -356
  8. package/lib/helpers/index.js +31 -31
  9. package/lib/helpers/lib/api/converter.js +129 -129
  10. package/lib/helpers/lib/api/index.js +46 -46
  11. package/lib/helpers/lib/errors.js +122 -122
  12. package/lib/helpers/lib/requestLayer.js +154 -154
  13. package/lib/helpers/lib/validator.js +192 -192
  14. package/lib/open_access/index.js +116 -116
  15. package/lib/services/analytics/index.js +1365 -1365
  16. package/lib/services/attempts/index.js +389 -389
  17. package/lib/services/auth/index.js +3708 -3708
  18. package/lib/services/authextn/index.js +1032 -1032
  19. package/lib/services/datasyncmanager/index.js +275 -275
  20. package/lib/services/drive/index.js +270 -270
  21. package/lib/services/integrations/index.js +525 -525
  22. package/lib/services/invitations/index.js +282 -282
  23. package/lib/services/product/index.js +343 -343
  24. package/lib/services/pub/index.js +530 -530
  25. package/lib/services/pushX/index.js +251 -251
  26. package/lib/services/pushX/pubnubClientWrapper.js +438 -438
  27. package/lib/services/rules/index.js +416 -416
  28. package/lib/services/spaces/index.js +999 -999
  29. package/lib/services/spacesextn/index.js +131 -131
  30. package/lib/services/superuser/index.js +160 -160
  31. package/lib/services/taxonomy/index.js +405 -405
  32. package/lib/services/workflows/index.js +406 -406
  33. package/lib/services/xapi/index.js +114 -114
  34. package/lib/token/index.js +120 -120
  35. package/lib/token/validations.js +85 -85
  36. package/package.json +5 -1
@@ -1,1032 +1,1032 @@
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
- /***********************************************************
22
- * comproDLS SDK AUTHEXTN Adaptor
23
- * Functions for calling AUTHEXTN API.
24
- ************************************************************/
25
-
26
- var q = require('q');
27
- var request = require('superagent');
28
- var helpers = require('../../helpers');
29
- var Agent = require('agentkeepalive');
30
- var requestLayer = require('../../helpers/lib/requestLayer');
31
-
32
- var DLSError = helpers.errors.DLSError;
33
-
34
- module.exports = authextn;
35
-
36
- var keepaliveAgent = new Agent({
37
- timeout: 60000,
38
- freeSocketTimeout: 30000
39
- });
40
-
41
- //AuthExtn Adaptor Contsructor
42
- function authextn() {
43
- return {
44
- // Gradeformat related APIs
45
- createGradeformat: createGradeformat.bind(this),
46
- updateGradeformat: updateGradeformat.bind(this),
47
- deleteGradeformat: deleteGradeformat.bind(this),
48
- getAllGradeformats: getAllGradeformats.bind(this),
49
- getParticularGradeformat: getParticularGradeformat.bind(this),
50
- associateGradeformatToClass: associateGradeformatToClass.bind(this),
51
- unassociateGradeformatFromClass: unassociateGradeformatFromClass.bind(this),
52
- updateClassGradeformatAssociation: updateClassGradeformatAssociation.bind(this),
53
- getParticularGradeformatOfAClass: getParticularGradeformatOfAClass.bind(this),
54
- getAllGradeformatsOfAClass: getAllGradeformatsOfAClass.bind(this),
55
- getClassesOfAGradeformat: getClassesOfAGradeformat.bind(this),
56
-
57
- // Assigned-path related APIs
58
- createUserAssignedPathEnrollments: createUserAssignedPathEnrollments.bind(this),
59
- deleteUserAssignedPathEnrollments: deleteUserAssignedPathEnrollments.bind(this),
60
-
61
- // Class related APIs
62
- getParticularClassV2: getParticularClassV2.bind(this),
63
-
64
- // Org Entitlement related APIs
65
- createOrgProductEntitlement: createOrgProductEntitlement.bind(this),
66
- updateOrgProductEntitlement: updateOrgProductEntitlement.bind(this),
67
- deleteOrgProductEntitlement: deleteOrgProductEntitlement.bind(this),
68
- getParticularOrgProductEntitlement: getParticularOrgProductEntitlement.bind(this),
69
- getAllOrgProductEntitlements: getAllOrgProductEntitlements.bind(this)
70
- };
71
- }
72
-
73
- /*********************************
74
- * Public Function definitions
75
- **********************************/
76
-
77
- /**
78
- * Wiki Link for SDK params
79
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#creategradeformatparams
80
- */
81
- function createGradeformat(options) {
82
- var self = this;
83
- // Initializing promise
84
- var dfd = q.defer();
85
-
86
- //Validations
87
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
88
- if(error) {
89
- dfd.reject(error);
90
- } else {
91
- if(options && options.body) {
92
- // Passed all validations, Contruct API url
93
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.gradeFormat;
94
- url = helpers.api.constructAPIUrl(url, {
95
- orgid: self.orgId
96
- });
97
-
98
- var requestAPI = request.post(url)
99
- .set('Content-Type', 'application/json')
100
- .set('Accept', 'application/json')
101
- .send(options.body);
102
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
103
-
104
- //Setup token in Authorization header
105
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
106
-
107
- requestAPI
108
- .agent(keepaliveAgent)
109
- .end(function(error, response) {
110
- if(error) {
111
- var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
112
- dfd.reject(err);
113
- }
114
- else { dfd.resolve(response.body); }
115
- });
116
- } else {
117
- var err = {};
118
- err.message = err.description = 'Mandatory param - body' +
119
- ' not found in request options.';
120
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
121
- dfd.reject(err);
122
- }
123
- }
124
- return dfd.promise;
125
- }
126
-
127
- /**
128
- * Wiki Link for SDK params
129
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#updategradeformatparams
130
- */
131
- function updateGradeformat(options) {
132
- // Initializing promise
133
- var deferred = q.defer();
134
- var self = this;
135
- var error = {};
136
-
137
- //Validations
138
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
139
- if(err) {
140
- deferred.reject(err);
141
- } else {
142
- if (options && options.gradeformat_id && options.body) {
143
- if (Object.keys(options.body).length !== 0) {
144
- // Passed all validations, Contruct API url
145
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.particularGradeFormat;
146
-
147
- url = helpers.api.constructAPIUrl(url, {
148
- orgid: self.orgId, gradeformat_id: options.gradeformat_id
149
- });
150
-
151
- var params = options.body;
152
- // Setup request with URL and Params
153
- var requestAPI = request.put(url)
154
- .set('Content-Type', 'application/json')
155
- .set('Accept', 'application/json')
156
- .send(params);
157
-
158
- if (self.traceid) {
159
- requestAPI.set('X-Amzn-Trace-Id', self.traceid);
160
- }
161
-
162
- //Setup token in Authorization header
163
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
164
-
165
- requestAPI
166
- .agent(keepaliveAgent)
167
- .end(function(error, response) {
168
- if (error) {
169
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
170
- deferred.reject(error);
171
- } else {
172
- deferred.resolve(response.body);
173
- }
174
- });
175
- } else {
176
- error.message = error.description = 'Body of the request cannot be empty.';
177
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
178
- deferred.reject(error);
179
- }
180
- } else {
181
- error.message = error.description = 'Mandatory params: gradeformat_id or body' +
182
- ' not found in the request options.';
183
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
184
- deferred.reject(error);
185
- }
186
- }
187
-
188
- return deferred.promise;
189
- }
190
-
191
- /**
192
- * Wiki Link for SDK params
193
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#deletegradeformatparams
194
- */
195
- function deleteGradeformat(options) {
196
- var self = this;
197
- var dfd = q.defer();
198
-
199
- //Validations
200
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
201
- if(error) {
202
- dfd.reject(error);
203
- } else {
204
- if(options && options.gradeformat_id) {
205
- // Passed all validations, Contruct API url
206
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.particularGradeFormat;
207
- url = helpers.api.constructAPIUrl(url, {
208
- orgid: self.orgId, gradeformat_id: options.gradeformat_id
209
- });
210
-
211
- // Setup request with URL and Params
212
- var requestAPI = request.delete(url);
213
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
214
-
215
- //Setup token in Authorization header
216
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
217
-
218
- requestAPI
219
- .agent(keepaliveAgent)
220
- .end(function (error, response) {
221
- if(error) {
222
- var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
223
- dfd.reject(err);
224
- }
225
- else { dfd.resolve(response.body); }
226
- });
227
- }
228
- else {
229
- var err = {};
230
- err.message = err.description = 'Mandatory params - gradeformat_id' +
231
- ' not found in request options.';
232
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
233
- dfd.reject(err);
234
- }
235
- }
236
-
237
- return dfd.promise;
238
- }
239
-
240
- /**
241
- * Wiki Link for SDK params
242
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticulargradeformatparams
243
- */
244
- function getParticularGradeformat (options) {
245
- // Initializing promise
246
- var deferred = q.defer();
247
- var self = this;
248
-
249
- //Validations
250
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
251
- if(err) {
252
- deferred.reject(err);
253
- } else {
254
- if (options && options.gradeformat_id) {
255
- // Passed all validations, Contruct API url
256
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.gradeFormat ;
257
-
258
- url = helpers.api.constructAPIUrl(url, {
259
- orgid: self.orgId
260
- });
261
-
262
- // Setup request with URL and Params
263
- var params = {gradeformat_id: options.gradeformat_id};
264
- var requestAPI = request.get(url).query(params);
265
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
266
-
267
- //Setup token in Authorization header
268
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
269
-
270
- requestAPI
271
- .agent(keepaliveAgent)
272
- .end(function(error, response) {
273
- if (error) {
274
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
275
- deferred.reject(error);
276
- } else {
277
- deferred.resolve(response.body.entities[0]);
278
- }
279
- });
280
- } else {
281
- var error = {};
282
- error.message = error.description = 'Mandatory params: gradeformat_id' +
283
- ' not found in request options.';
284
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
285
- deferred.reject(error);
286
- }
287
- }
288
- return deferred.promise;
289
- }
290
-
291
- /**
292
- * Wiki Link for SDK params
293
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getallgradeformatsparams
294
- */
295
- function getAllGradeformats (options) {
296
- // Initializing promise
297
- var deferred = q.defer();
298
- var self = this;
299
-
300
- //Validations
301
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
302
- if(err) {
303
- deferred.reject(err);
304
- } else {
305
- // Passed all validations, Contruct API url
306
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.gradeFormat;
307
-
308
- url = helpers.api.constructAPIUrl(url, {
309
- orgid: self.orgId
310
- });
311
-
312
- // Setup request with URL and Params
313
- var params = {};
314
- if(options && options.cursor){ params.cursor = options.cursor; }
315
-
316
- var requestAPI = request.get(url).query(params);
317
-
318
- if (self.traceid) {
319
- requestAPI.set('X-Amzn-Trace-Id', self.traceid);
320
- }
321
-
322
- //Setup token in Authorization header
323
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
324
-
325
- requestAPI
326
- .agent(keepaliveAgent)
327
- .end(function(error, response) {
328
- if (error) {
329
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
330
- deferred.reject(error);
331
- } else {
332
- deferred.resolve(response.body);
333
- }
334
- });
335
- }
336
- return deferred.promise;
337
- }
338
-
339
- /**
340
- * Wiki Link for SDK params
341
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#associategradeformattoclassparams
342
- */
343
- function associateGradeformatToClass(options) {
344
- var self = this;
345
- // Initializing promise
346
- var deferred = q.defer();
347
- // Validations
348
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
349
- if (error) {
350
- deferred.reject(error);
351
- } else {
352
- if (options && options.classid && options.gradeformat_id && options.body) {
353
- // Passed all validations, Contruct API url
354
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
355
- self.config.AUTHEXTN_API_URLS.classGradeformatAssociation;
356
-
357
- url = helpers.api.constructAPIUrl(url, {
358
- orgid: self.orgId,
359
- classid: options.classid,
360
- gradeformat_id: options.gradeformat_id
361
- });
362
-
363
- // Setup request with URL and Params
364
- var requestAPI = request
365
- .post(url)
366
- .set('Content-Type', 'application/json')
367
- .set('Accept', 'application/json')
368
- .send(options.body);
369
-
370
- // Setup traceid in request header
371
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
372
-
373
- // Setup token in Authorization header
374
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
375
-
376
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
377
- if (error) {
378
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
379
- deferred.reject(error);
380
- } else {
381
- deferred.resolve(response.body);
382
- }
383
- });
384
- } else {
385
- error = {};
386
- error.message = error.description = 'Mandatory params - classid or gradeformat_id or body' +
387
- ' not found in request options.';
388
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
389
- deferred.reject(error);
390
- }
391
- }
392
-
393
- return deferred.promise;
394
- }
395
-
396
- /**
397
- * Wiki Link for SDK params
398
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#unassociategradeformatfromclassparams
399
- */
400
- function unassociateGradeformatFromClass(options) {
401
- var self = this;
402
- // Initializing promise
403
- var deferred = q.defer();
404
- // Validations
405
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
406
- if (error) {
407
- deferred.reject(error);
408
- } else {
409
- if (options && options.classid && options.gradeformat_id) {
410
- // Passed all validations, Contruct API url
411
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
412
- self.config.AUTHEXTN_API_URLS.classGradeformatAssociation;
413
-
414
- url = helpers.api.constructAPIUrl(url, {
415
- orgid: self.orgId,
416
- classid: options.classid,
417
- gradeformat_id: options.gradeformat_id
418
- });
419
-
420
- // Setup request with URL
421
- var requestAPI = request.delete(url);
422
-
423
- // Setup traceid in request header
424
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
425
-
426
- // Setup token in Authorization header
427
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
428
-
429
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
430
- if (error) {
431
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
432
- deferred.reject(error);
433
- } else {
434
- deferred.resolve(response.body);
435
- }
436
- });
437
- } else {
438
- error = {};
439
- error.message = error.description = 'Mandatory params - classid or gradeformat_id' +
440
- ' not found in request options.';
441
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
442
- deferred.reject(error);
443
- }
444
- }
445
-
446
- return deferred.promise;
447
- }
448
-
449
- /**
450
- * Wiki Link for SDK params
451
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#updateclassgradeformatassociationparams
452
- */
453
- function updateClassGradeformatAssociation(options) {
454
- var self = this;
455
- // Initializing promise
456
- var deferred = q.defer();
457
- // Validations
458
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
459
- if (error) {
460
- deferred.reject(error);
461
- } else {
462
- if (options && options.classid && options.gradeformat_id && options.body) {
463
- // Passed all validations, Contruct API url
464
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
465
- self.config.AUTHEXTN_API_URLS.classGradeformatAssociation;
466
-
467
- url = helpers.api.constructAPIUrl(url, {
468
- orgid: self.orgId,
469
- classid: options.classid,
470
- gradeformat_id: options.gradeformat_id
471
- });
472
-
473
- // Setup request with URL and Params
474
- var params = options.body;
475
- var requestAPI = request.put(url)
476
- .set('Content-Type', 'application/json')
477
- .set('Accept', 'application/json')
478
- .send(params);
479
-
480
- // Setup traceid in request header
481
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
482
-
483
- // Setup token in Authorization header
484
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
485
-
486
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
487
- if (error) {
488
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
489
- deferred.reject(error);
490
- } else {
491
- deferred.resolve(response.body);
492
- }
493
- });
494
- } else {
495
- error = {};
496
- error.message = error.description = 'Mandatory params: classid or gradeformat_id or body' +
497
- ' not found in the request options.';
498
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
499
- deferred.reject(error);
500
- }
501
- }
502
-
503
- return deferred.promise;
504
- }
505
-
506
- /**
507
- * Wiki Link for SDK params
508
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticulargradeformatofaclassparams
509
- */
510
- function getParticularGradeformatOfAClass(options) {
511
- var self = this;
512
- // Initializing promise
513
- var deferred = q.defer();
514
- // Validations
515
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
516
- if (error) {
517
- deferred.reject(error);
518
- } else {
519
- if (options && options.classid && options.gradeformat_id) {
520
- // Passed all validations, Contruct API url
521
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.classGradeformats;
522
-
523
- url = helpers.api.constructAPIUrl(url, {
524
- orgid: self.orgId,
525
- classid: options.classid
526
- });
527
-
528
- // Setup request with URL and Params
529
- var params = { gradeformat_id: options.gradeformat_id };
530
- var requestAPI = request.get(url).query(params);
531
-
532
- // Setup traceid in request header
533
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
534
-
535
- // Setup token in Authorization header
536
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
537
-
538
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
539
- if (error) {
540
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
541
- deferred.reject(error);
542
- } else {
543
- deferred.resolve(response.body.entities[0]);
544
- }
545
- });
546
- } else {
547
- error = {};
548
- error.message = error.description = 'Mandatory params: classid or gradeformat_id' +
549
- ' not found in request options.';
550
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
551
- deferred.reject(error);
552
- }
553
- }
554
-
555
- return deferred.promise;
556
- }
557
-
558
- /**
559
- * Wiki Link for SDK params
560
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getallgradeformatsofaclassparams
561
- */
562
- function getAllGradeformatsOfAClass(options) {
563
- var self = this;
564
- // Initializing promise
565
- var deferred = q.defer();
566
- // Validations
567
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
568
- if (error) {
569
- deferred.reject(error);
570
- } else {
571
- if (options && options.classid) {
572
- // Passed all validations, Contruct API url
573
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.classGradeformats;
574
-
575
- url = helpers.api.constructAPIUrl(url, {
576
- orgid: self.orgId,
577
- classid: options.classid
578
- });
579
-
580
- // Setup request with URL and Query Params
581
- var params = {};
582
- if (options.cursor) { params.cursor = options.cursor; }
583
-
584
- var requestAPI = request.get(url).query(params);
585
-
586
- // Setup traceid in request header
587
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
588
-
589
- // Setup token in Authorization header
590
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
591
-
592
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
593
- if (error) {
594
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
595
- deferred.reject(error);
596
- } else {
597
- deferred.resolve(response.body);
598
- }
599
- });
600
- } else {
601
- error = {};
602
- error.message = error.description = 'Mandatory params: classid' +
603
- ' not found in request options.';
604
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
605
- deferred.reject(error);
606
- }
607
- }
608
-
609
- return deferred.promise;
610
- }
611
-
612
- /**
613
- * Wiki Link for SDK params
614
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getclassesofagradeformatparams
615
- */
616
- function getClassesOfAGradeformat(options) {
617
- var self = this;
618
- // Initializing promise
619
- var deferred = q.defer();
620
- // Validations
621
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
622
- if (error) {
623
- deferred.reject(error);
624
- } else {
625
- if (options && options.gradeformat_id) {
626
- // Passed all validations, Contruct API url
627
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
628
- self.config.AUTHEXTN_API_URLS.gradeformatClasses;
629
-
630
- url = helpers.api.constructAPIUrl(url, {
631
- orgid: self.orgId,
632
- gradeformat_id: options.gradeformat_id
633
- });
634
-
635
- // Setup request with URL and Query Params
636
- var params = {};
637
- if (options.cursor) { params.cursor = options.cursor; }
638
-
639
- var requestAPI = request.get(url).query(params);
640
-
641
- // Setup traceid in request header
642
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
643
-
644
- // Setup token in Authorization header
645
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
646
-
647
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
648
- if (error) {
649
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
650
- deferred.reject(error);
651
- } else {
652
- deferred.resolve(response.body);
653
- }
654
- });
655
- } else {
656
- error = {};
657
- error.message = error.description = 'Mandatory params: gradeformat_id' +
658
- ' not found in request options.';
659
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
660
- deferred.reject(error);
661
- }
662
- }
663
-
664
- return deferred.promise;
665
- }
666
-
667
- /**
668
- * Wiki Link for SDK params
669
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#createuserassignedpathenrollmentsparams
670
- */
671
- function createUserAssignedPathEnrollments(options) {
672
- var self = this;
673
- // Initializing promise
674
- var dfd = q.defer();
675
-
676
- //Validations
677
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
678
- if(error) {
679
- dfd.reject(error);
680
- } else {
681
- if(options && options.classid && options.assignedpathid && options.body) {
682
- // Passed all validations, Contruct API url
683
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
684
- self.config.AUTHEXTN_API_URLS.userAssignedPaths;
685
- url = helpers.api.constructAPIUrl(url, {
686
- orgid: self.orgId,
687
- classid: options.classid,
688
- assignedpathid: options.assignedpathid,
689
- });
690
-
691
- var requestAPI = request.post(url)
692
- .set('Content-Type', 'application/json')
693
- .set('Accept', 'application/json')
694
- .send(options.body);
695
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
696
-
697
- //Setup token in Authorization header
698
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
699
-
700
- requestAPI
701
- .agent(keepaliveAgent)
702
- .end(function(error, response) {
703
- if(error) {
704
- var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
705
- dfd.reject(err);
706
- }
707
- else { dfd.resolve(response.body); }
708
- });
709
- } else {
710
- var err = {};
711
- err.message = err.description = 'Mandatory param: classid, assignedpathid, body' +
712
- ' not found in request options.';
713
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
714
- dfd.reject(err);
715
- }
716
- }
717
- return dfd.promise;
718
- }
719
-
720
- /**
721
- * Wiki Link for SDK params
722
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#deleteuserassignedpathenrollmentsparams
723
- */
724
- function deleteUserAssignedPathEnrollments(options) {
725
- var self = this;
726
- // Initializing promise
727
- var dfd = q.defer();
728
-
729
- //Validations
730
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
731
- if(error) {
732
- dfd.reject(error);
733
- } else {
734
- if(options && options.classid && options.assignedpathid && options.body) {
735
- // Passed all validations, Contruct API url
736
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
737
- self.config.AUTHEXTN_API_URLS.userAssignedPaths;
738
- url = helpers.api.constructAPIUrl(url, {
739
- orgid: self.orgId,
740
- classid: options.classid,
741
- assignedpathid: options.assignedpathid,
742
- });
743
-
744
- var requestAPI = request.delete(url)
745
- .set('Content-Type', 'application/json')
746
- .set('Accept', 'application/json')
747
- .send(options.body);
748
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
749
-
750
- //Setup token in Authorization header
751
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
752
-
753
- requestAPI
754
- .agent(keepaliveAgent)
755
- .end(function(error, response) {
756
- if(error) {
757
- var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
758
- dfd.reject(err);
759
- }
760
- else { dfd.resolve(response.body); }
761
- });
762
- } else {
763
- var err = {};
764
- err.message = err.description = 'Mandatory param: classid, assignedpathid, body' +
765
- ' not found in request options.';
766
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
767
- dfd.reject(err);
768
- }
769
- }
770
- return dfd.promise;
771
- }
772
-
773
- /**
774
- * Wiki Link for SDK params
775
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticularclassv2params
776
- */
777
- function getParticularClassV2(options) {
778
- var self = this;
779
- //Initializing promise
780
- var deferred = q.defer();
781
-
782
- //Validations
783
- var error = helpers.validations.isAuthenticated(self.orgId, self.token);
784
- if (error) {
785
- deferred.reject(error);
786
- } else {
787
- if (options && options.classId) {
788
- // Passed all validations, Contruct the API URL
789
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.particularClass;
790
- url = helpers.api.constructAPIUrl(url, { orgId: self.orgId, classId: options.classId });
791
-
792
- // Setup request with URL and Query Params
793
- var params = { productDetails: options.productDetails, bundleDetails: options.bundleDetails };
794
- var requestAPI = request.get(url).query(params);
795
-
796
- // Setup 'traceid' in request header
797
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
798
-
799
- // Setup 'token' in Authorization header
800
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
801
-
802
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
803
- if (error) {
804
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
805
- deferred.reject(error);
806
- } else {
807
- deferred.resolve(response.body);
808
- }
809
- });
810
- } else {
811
- error = {};
812
- error.message = error.description = 'Mandatory field \'classId\' not found in request options.';
813
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
814
- deferred.reject(error);
815
- }
816
- }
817
-
818
- return deferred.promise;
819
- }
820
-
821
- /**
822
- * Wiki Link for SDK params
823
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#createorgproductentitlementparams
824
- */
825
- function createOrgProductEntitlement(options) {
826
- var self = this;
827
- // Initializing promise
828
- var dfd = q.defer();
829
- if (!self.orgId) {
830
- var err = {};
831
- err.message = err.description = 'Mandatory param: orgid not found in options while ' +
832
- 'initializing comprodls-sdk.';
833
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
834
- dfd.reject(err);
835
- } else {
836
- if (options && options.productcode) {
837
- // Passed all validations, Contruct API url
838
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
839
- self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
840
- url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
841
-
842
- var requestAPI = request.post(url)
843
- .set('Content-Type', 'application/json')
844
- .set('Accept', 'application/json')
845
- .send(options);
846
-
847
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
848
-
849
- requestAPI
850
- .agent(keepaliveAgent)
851
- .end(function(error, response) {
852
- if (error) {
853
- var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
854
- dfd.reject(err);
855
- }
856
- else { dfd.resolve(response.body); }
857
- });
858
- } else {
859
- var err = {};
860
- err.message = err.description = 'Mandatory param: productcode not found in request options.';
861
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
862
- dfd.reject(err);
863
- }
864
- }
865
- return dfd.promise;
866
- }
867
-
868
- /**
869
- * Wiki Link for SDK params
870
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#updateorgproductentitlementparams
871
- */
872
- function updateOrgProductEntitlement(options) {
873
- var self = this;
874
- // Initializing promise
875
- var dfd = q.defer();
876
-
877
- if (!self.orgId) {
878
- var err = {};
879
- err.message = err.description = 'Mandatory param: orgid not found in options while ' +
880
- 'initializing comprodls-sdk.';
881
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
882
- dfd.reject(err);
883
- } else {
884
- if (options && options.productcode) {
885
- // Passed all validations, Contruct API url
886
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
887
- self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
888
- url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
889
-
890
- var requestAPI = request.put(url)
891
- .set('Content-Type', 'application/json')
892
- .set('Accept', 'application/json')
893
- .send(options);
894
-
895
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
896
-
897
- requestAPI
898
- .agent(keepaliveAgent)
899
- .end(function(error, response) {
900
- if (error) {
901
- var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
902
- dfd.reject(err);
903
- }
904
- else { dfd.resolve(response.body); }
905
- });
906
- } else {
907
- var err = {};
908
- err.message = err.description = 'Mandatory param: productcode not found in request options.';
909
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
910
- dfd.reject(err);
911
- }
912
- }
913
-
914
- return dfd.promise;
915
- }
916
-
917
- /**
918
- * Wiki Link for SDK params
919
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#deleteorgproductentitlementparams
920
- */
921
- function deleteOrgProductEntitlement(options) {
922
- var self = this;
923
-
924
- // Validate productcode
925
- if (!(options && options.productcode)) {
926
- var err = {};
927
- err.message = err.description = 'Mandatory param: productcode not found in request options.';
928
- return Promise.reject(new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err));
929
- }
930
-
931
- // Authenticate token
932
- var error = helpers.validations.isAuthenticatedV2(self.orgId, self.token);
933
- if (error) { return Promise.reject(error); }
934
-
935
- // Construct API URL
936
- var url = helpers.api.constructAPIUrl(
937
- self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.orgProductEntitlement,
938
- { orgid: self.orgId }
939
- );
940
-
941
- // Prepare request parameters & execute request
942
- var reqOptions = {
943
- params: options,
944
- headers: { traceid: self.traceid, token: self.token }
945
- };
946
- return requestLayer.delete(url, reqOptions)
947
- .then(function (response) {
948
- return response.body;
949
- })
950
- .catch(function (err) {
951
- throw new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
952
- });
953
- }
954
-
955
- /**
956
- * Wiki Link for SDK params
957
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticularorgproductentitlementparams
958
- */
959
- function getParticularOrgProductEntitlement(options) {
960
- var self = this;
961
- //Initializing promise
962
- var deferred = q.defer();
963
-
964
- if (options && options.productcode) {
965
- // Passed all validations, Contruct the API URL
966
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
967
- self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
968
- url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
969
-
970
- // Setup request with URL and Query Params
971
- var params = { productcode: options.productcode };
972
- var requestAPI = request.get(url).query(params);
973
-
974
- // Setup 'traceid' in request header
975
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
976
-
977
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
978
- if (error) {
979
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
980
- deferred.reject(error);
981
- } else {
982
- deferred.resolve(response.body);
983
- }
984
- });
985
- } else {
986
- var error = {};
987
- error.message = error.description = 'Mandatory field \'productcode\' not found '+
988
- 'in request options.';
989
- error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
990
- deferred.reject(error);
991
- }
992
-
993
- return deferred.promise;
994
- }
995
-
996
- /**
997
- * Wiki Link for SDK params
998
- * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getallorgproductentitlementsparams
999
- */
1000
- function getAllOrgProductEntitlements(options) {
1001
- var self = this;
1002
- //Initializing promise
1003
- var deferred = q.defer();
1004
-
1005
- // Contruct the API URL
1006
- var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
1007
- self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
1008
- url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
1009
-
1010
- // Setup request with URL and Query Params
1011
- var params = { productcode: options.productcode };
1012
-
1013
- if (options.status) { params.status = options.status; }
1014
- if (options.hasOwnProperty('expired')) { params.expired = options.expired; }
1015
- if (options.cursor) { params.cursor = options.cursor; }
1016
-
1017
- var requestAPI = request.get(url).query(params);
1018
-
1019
- // Setup 'traceid' in request header
1020
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
1021
-
1022
- requestAPI.agent(keepaliveAgent).end(function (error, response) {
1023
- if (error) {
1024
- error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
1025
- deferred.reject(error);
1026
- } else {
1027
- deferred.resolve(response.body);
1028
- }
1029
- });
1030
-
1031
- return deferred.promise;
1032
- }
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
+ /***********************************************************
22
+ * comproDLS SDK AUTHEXTN Adaptor
23
+ * Functions for calling AUTHEXTN API.
24
+ ************************************************************/
25
+
26
+ var q = require('q');
27
+ var request = require('superagent');
28
+ var helpers = require('../../helpers');
29
+ var Agent = require('agentkeepalive');
30
+ var requestLayer = require('../../helpers/lib/requestLayer');
31
+
32
+ var DLSError = helpers.errors.DLSError;
33
+
34
+ module.exports = authextn;
35
+
36
+ var keepaliveAgent = new Agent({
37
+ timeout: 60000,
38
+ freeSocketTimeout: 30000
39
+ });
40
+
41
+ //AuthExtn Adaptor Contsructor
42
+ function authextn() {
43
+ return {
44
+ // Gradeformat related APIs
45
+ createGradeformat: createGradeformat.bind(this),
46
+ updateGradeformat: updateGradeformat.bind(this),
47
+ deleteGradeformat: deleteGradeformat.bind(this),
48
+ getAllGradeformats: getAllGradeformats.bind(this),
49
+ getParticularGradeformat: getParticularGradeformat.bind(this),
50
+ associateGradeformatToClass: associateGradeformatToClass.bind(this),
51
+ unassociateGradeformatFromClass: unassociateGradeformatFromClass.bind(this),
52
+ updateClassGradeformatAssociation: updateClassGradeformatAssociation.bind(this),
53
+ getParticularGradeformatOfAClass: getParticularGradeformatOfAClass.bind(this),
54
+ getAllGradeformatsOfAClass: getAllGradeformatsOfAClass.bind(this),
55
+ getClassesOfAGradeformat: getClassesOfAGradeformat.bind(this),
56
+
57
+ // Assigned-path related APIs
58
+ createUserAssignedPathEnrollments: createUserAssignedPathEnrollments.bind(this),
59
+ deleteUserAssignedPathEnrollments: deleteUserAssignedPathEnrollments.bind(this),
60
+
61
+ // Class related APIs
62
+ getParticularClassV2: getParticularClassV2.bind(this),
63
+
64
+ // Org Entitlement related APIs
65
+ createOrgProductEntitlement: createOrgProductEntitlement.bind(this),
66
+ updateOrgProductEntitlement: updateOrgProductEntitlement.bind(this),
67
+ deleteOrgProductEntitlement: deleteOrgProductEntitlement.bind(this),
68
+ getParticularOrgProductEntitlement: getParticularOrgProductEntitlement.bind(this),
69
+ getAllOrgProductEntitlements: getAllOrgProductEntitlements.bind(this)
70
+ };
71
+ }
72
+
73
+ /*********************************
74
+ * Public Function definitions
75
+ **********************************/
76
+
77
+ /**
78
+ * Wiki Link for SDK params
79
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#creategradeformatparams
80
+ */
81
+ function createGradeformat(options) {
82
+ var self = this;
83
+ // Initializing promise
84
+ var dfd = q.defer();
85
+
86
+ //Validations
87
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
88
+ if(error) {
89
+ dfd.reject(error);
90
+ } else {
91
+ if(options && options.body) {
92
+ // Passed all validations, Contruct API url
93
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.gradeFormat;
94
+ url = helpers.api.constructAPIUrl(url, {
95
+ orgid: self.orgId
96
+ });
97
+
98
+ var requestAPI = request.post(url)
99
+ .set('Content-Type', 'application/json')
100
+ .set('Accept', 'application/json')
101
+ .send(options.body);
102
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
103
+
104
+ //Setup token in Authorization header
105
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
106
+
107
+ requestAPI
108
+ .agent(keepaliveAgent)
109
+ .end(function(error, response) {
110
+ if(error) {
111
+ var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
112
+ dfd.reject(err);
113
+ }
114
+ else { dfd.resolve(response.body); }
115
+ });
116
+ } else {
117
+ var err = {};
118
+ err.message = err.description = 'Mandatory param - body' +
119
+ ' not found in request options.';
120
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
121
+ dfd.reject(err);
122
+ }
123
+ }
124
+ return dfd.promise;
125
+ }
126
+
127
+ /**
128
+ * Wiki Link for SDK params
129
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#updategradeformatparams
130
+ */
131
+ function updateGradeformat(options) {
132
+ // Initializing promise
133
+ var deferred = q.defer();
134
+ var self = this;
135
+ var error = {};
136
+
137
+ //Validations
138
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
139
+ if(err) {
140
+ deferred.reject(err);
141
+ } else {
142
+ if (options && options.gradeformat_id && options.body) {
143
+ if (Object.keys(options.body).length !== 0) {
144
+ // Passed all validations, Contruct API url
145
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.particularGradeFormat;
146
+
147
+ url = helpers.api.constructAPIUrl(url, {
148
+ orgid: self.orgId, gradeformat_id: options.gradeformat_id
149
+ });
150
+
151
+ var params = options.body;
152
+ // Setup request with URL and Params
153
+ var requestAPI = request.put(url)
154
+ .set('Content-Type', 'application/json')
155
+ .set('Accept', 'application/json')
156
+ .send(params);
157
+
158
+ if (self.traceid) {
159
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
160
+ }
161
+
162
+ //Setup token in Authorization header
163
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
164
+
165
+ requestAPI
166
+ .agent(keepaliveAgent)
167
+ .end(function(error, response) {
168
+ if (error) {
169
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
170
+ deferred.reject(error);
171
+ } else {
172
+ deferred.resolve(response.body);
173
+ }
174
+ });
175
+ } else {
176
+ error.message = error.description = 'Body of the request cannot be empty.';
177
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
178
+ deferred.reject(error);
179
+ }
180
+ } else {
181
+ error.message = error.description = 'Mandatory params: gradeformat_id or body' +
182
+ ' not found in the request options.';
183
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
184
+ deferred.reject(error);
185
+ }
186
+ }
187
+
188
+ return deferred.promise;
189
+ }
190
+
191
+ /**
192
+ * Wiki Link for SDK params
193
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#deletegradeformatparams
194
+ */
195
+ function deleteGradeformat(options) {
196
+ var self = this;
197
+ var dfd = q.defer();
198
+
199
+ //Validations
200
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
201
+ if(error) {
202
+ dfd.reject(error);
203
+ } else {
204
+ if(options && options.gradeformat_id) {
205
+ // Passed all validations, Contruct API url
206
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.particularGradeFormat;
207
+ url = helpers.api.constructAPIUrl(url, {
208
+ orgid: self.orgId, gradeformat_id: options.gradeformat_id
209
+ });
210
+
211
+ // Setup request with URL and Params
212
+ var requestAPI = request.delete(url);
213
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
214
+
215
+ //Setup token in Authorization header
216
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
217
+
218
+ requestAPI
219
+ .agent(keepaliveAgent)
220
+ .end(function (error, response) {
221
+ if(error) {
222
+ var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
223
+ dfd.reject(err);
224
+ }
225
+ else { dfd.resolve(response.body); }
226
+ });
227
+ }
228
+ else {
229
+ var err = {};
230
+ err.message = err.description = 'Mandatory params - gradeformat_id' +
231
+ ' not found in request options.';
232
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
233
+ dfd.reject(err);
234
+ }
235
+ }
236
+
237
+ return dfd.promise;
238
+ }
239
+
240
+ /**
241
+ * Wiki Link for SDK params
242
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticulargradeformatparams
243
+ */
244
+ function getParticularGradeformat (options) {
245
+ // Initializing promise
246
+ var deferred = q.defer();
247
+ var self = this;
248
+
249
+ //Validations
250
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
251
+ if(err) {
252
+ deferred.reject(err);
253
+ } else {
254
+ if (options && options.gradeformat_id) {
255
+ // Passed all validations, Contruct API url
256
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.gradeFormat ;
257
+
258
+ url = helpers.api.constructAPIUrl(url, {
259
+ orgid: self.orgId
260
+ });
261
+
262
+ // Setup request with URL and Params
263
+ var params = {gradeformat_id: options.gradeformat_id};
264
+ var requestAPI = request.get(url).query(params);
265
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
266
+
267
+ //Setup token in Authorization header
268
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
269
+
270
+ requestAPI
271
+ .agent(keepaliveAgent)
272
+ .end(function(error, response) {
273
+ if (error) {
274
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
275
+ deferred.reject(error);
276
+ } else {
277
+ deferred.resolve(response.body.entities[0]);
278
+ }
279
+ });
280
+ } else {
281
+ var error = {};
282
+ error.message = error.description = 'Mandatory params: gradeformat_id' +
283
+ ' not found in request options.';
284
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
285
+ deferred.reject(error);
286
+ }
287
+ }
288
+ return deferred.promise;
289
+ }
290
+
291
+ /**
292
+ * Wiki Link for SDK params
293
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getallgradeformatsparams
294
+ */
295
+ function getAllGradeformats (options) {
296
+ // Initializing promise
297
+ var deferred = q.defer();
298
+ var self = this;
299
+
300
+ //Validations
301
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
302
+ if(err) {
303
+ deferred.reject(err);
304
+ } else {
305
+ // Passed all validations, Contruct API url
306
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.gradeFormat;
307
+
308
+ url = helpers.api.constructAPIUrl(url, {
309
+ orgid: self.orgId
310
+ });
311
+
312
+ // Setup request with URL and Params
313
+ var params = {};
314
+ if(options && options.cursor){ params.cursor = options.cursor; }
315
+
316
+ var requestAPI = request.get(url).query(params);
317
+
318
+ if (self.traceid) {
319
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
320
+ }
321
+
322
+ //Setup token in Authorization header
323
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
324
+
325
+ requestAPI
326
+ .agent(keepaliveAgent)
327
+ .end(function(error, response) {
328
+ if (error) {
329
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
330
+ deferred.reject(error);
331
+ } else {
332
+ deferred.resolve(response.body);
333
+ }
334
+ });
335
+ }
336
+ return deferred.promise;
337
+ }
338
+
339
+ /**
340
+ * Wiki Link for SDK params
341
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#associategradeformattoclassparams
342
+ */
343
+ function associateGradeformatToClass(options) {
344
+ var self = this;
345
+ // Initializing promise
346
+ var deferred = q.defer();
347
+ // Validations
348
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
349
+ if (error) {
350
+ deferred.reject(error);
351
+ } else {
352
+ if (options && options.classid && options.gradeformat_id && options.body) {
353
+ // Passed all validations, Contruct API url
354
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
355
+ self.config.AUTHEXTN_API_URLS.classGradeformatAssociation;
356
+
357
+ url = helpers.api.constructAPIUrl(url, {
358
+ orgid: self.orgId,
359
+ classid: options.classid,
360
+ gradeformat_id: options.gradeformat_id
361
+ });
362
+
363
+ // Setup request with URL and Params
364
+ var requestAPI = request
365
+ .post(url)
366
+ .set('Content-Type', 'application/json')
367
+ .set('Accept', 'application/json')
368
+ .send(options.body);
369
+
370
+ // Setup traceid in request header
371
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
372
+
373
+ // Setup token in Authorization header
374
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
375
+
376
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
377
+ if (error) {
378
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
379
+ deferred.reject(error);
380
+ } else {
381
+ deferred.resolve(response.body);
382
+ }
383
+ });
384
+ } else {
385
+ error = {};
386
+ error.message = error.description = 'Mandatory params - classid or gradeformat_id or body' +
387
+ ' not found in request options.';
388
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
389
+ deferred.reject(error);
390
+ }
391
+ }
392
+
393
+ return deferred.promise;
394
+ }
395
+
396
+ /**
397
+ * Wiki Link for SDK params
398
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#unassociategradeformatfromclassparams
399
+ */
400
+ function unassociateGradeformatFromClass(options) {
401
+ var self = this;
402
+ // Initializing promise
403
+ var deferred = q.defer();
404
+ // Validations
405
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
406
+ if (error) {
407
+ deferred.reject(error);
408
+ } else {
409
+ if (options && options.classid && options.gradeformat_id) {
410
+ // Passed all validations, Contruct API url
411
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
412
+ self.config.AUTHEXTN_API_URLS.classGradeformatAssociation;
413
+
414
+ url = helpers.api.constructAPIUrl(url, {
415
+ orgid: self.orgId,
416
+ classid: options.classid,
417
+ gradeformat_id: options.gradeformat_id
418
+ });
419
+
420
+ // Setup request with URL
421
+ var requestAPI = request.delete(url);
422
+
423
+ // Setup traceid in request header
424
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
425
+
426
+ // Setup token in Authorization header
427
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
428
+
429
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
430
+ if (error) {
431
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
432
+ deferred.reject(error);
433
+ } else {
434
+ deferred.resolve(response.body);
435
+ }
436
+ });
437
+ } else {
438
+ error = {};
439
+ error.message = error.description = 'Mandatory params - classid or gradeformat_id' +
440
+ ' not found in request options.';
441
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
442
+ deferred.reject(error);
443
+ }
444
+ }
445
+
446
+ return deferred.promise;
447
+ }
448
+
449
+ /**
450
+ * Wiki Link for SDK params
451
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#updateclassgradeformatassociationparams
452
+ */
453
+ function updateClassGradeformatAssociation(options) {
454
+ var self = this;
455
+ // Initializing promise
456
+ var deferred = q.defer();
457
+ // Validations
458
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
459
+ if (error) {
460
+ deferred.reject(error);
461
+ } else {
462
+ if (options && options.classid && options.gradeformat_id && options.body) {
463
+ // Passed all validations, Contruct API url
464
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
465
+ self.config.AUTHEXTN_API_URLS.classGradeformatAssociation;
466
+
467
+ url = helpers.api.constructAPIUrl(url, {
468
+ orgid: self.orgId,
469
+ classid: options.classid,
470
+ gradeformat_id: options.gradeformat_id
471
+ });
472
+
473
+ // Setup request with URL and Params
474
+ var params = options.body;
475
+ var requestAPI = request.put(url)
476
+ .set('Content-Type', 'application/json')
477
+ .set('Accept', 'application/json')
478
+ .send(params);
479
+
480
+ // Setup traceid in request header
481
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
482
+
483
+ // Setup token in Authorization header
484
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
485
+
486
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
487
+ if (error) {
488
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
489
+ deferred.reject(error);
490
+ } else {
491
+ deferred.resolve(response.body);
492
+ }
493
+ });
494
+ } else {
495
+ error = {};
496
+ error.message = error.description = 'Mandatory params: classid or gradeformat_id or body' +
497
+ ' not found in the request options.';
498
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
499
+ deferred.reject(error);
500
+ }
501
+ }
502
+
503
+ return deferred.promise;
504
+ }
505
+
506
+ /**
507
+ * Wiki Link for SDK params
508
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticulargradeformatofaclassparams
509
+ */
510
+ function getParticularGradeformatOfAClass(options) {
511
+ var self = this;
512
+ // Initializing promise
513
+ var deferred = q.defer();
514
+ // Validations
515
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
516
+ if (error) {
517
+ deferred.reject(error);
518
+ } else {
519
+ if (options && options.classid && options.gradeformat_id) {
520
+ // Passed all validations, Contruct API url
521
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.classGradeformats;
522
+
523
+ url = helpers.api.constructAPIUrl(url, {
524
+ orgid: self.orgId,
525
+ classid: options.classid
526
+ });
527
+
528
+ // Setup request with URL and Params
529
+ var params = { gradeformat_id: options.gradeformat_id };
530
+ var requestAPI = request.get(url).query(params);
531
+
532
+ // Setup traceid in request header
533
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
534
+
535
+ // Setup token in Authorization header
536
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
537
+
538
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
539
+ if (error) {
540
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
541
+ deferred.reject(error);
542
+ } else {
543
+ deferred.resolve(response.body.entities[0]);
544
+ }
545
+ });
546
+ } else {
547
+ error = {};
548
+ error.message = error.description = 'Mandatory params: classid or gradeformat_id' +
549
+ ' not found in request options.';
550
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
551
+ deferred.reject(error);
552
+ }
553
+ }
554
+
555
+ return deferred.promise;
556
+ }
557
+
558
+ /**
559
+ * Wiki Link for SDK params
560
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getallgradeformatsofaclassparams
561
+ */
562
+ function getAllGradeformatsOfAClass(options) {
563
+ var self = this;
564
+ // Initializing promise
565
+ var deferred = q.defer();
566
+ // Validations
567
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
568
+ if (error) {
569
+ deferred.reject(error);
570
+ } else {
571
+ if (options && options.classid) {
572
+ // Passed all validations, Contruct API url
573
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.classGradeformats;
574
+
575
+ url = helpers.api.constructAPIUrl(url, {
576
+ orgid: self.orgId,
577
+ classid: options.classid
578
+ });
579
+
580
+ // Setup request with URL and Query Params
581
+ var params = {};
582
+ if (options.cursor) { params.cursor = options.cursor; }
583
+
584
+ var requestAPI = request.get(url).query(params);
585
+
586
+ // Setup traceid in request header
587
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
588
+
589
+ // Setup token in Authorization header
590
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
591
+
592
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
593
+ if (error) {
594
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
595
+ deferred.reject(error);
596
+ } else {
597
+ deferred.resolve(response.body);
598
+ }
599
+ });
600
+ } else {
601
+ error = {};
602
+ error.message = error.description = 'Mandatory params: classid' +
603
+ ' not found in request options.';
604
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
605
+ deferred.reject(error);
606
+ }
607
+ }
608
+
609
+ return deferred.promise;
610
+ }
611
+
612
+ /**
613
+ * Wiki Link for SDK params
614
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getclassesofagradeformatparams
615
+ */
616
+ function getClassesOfAGradeformat(options) {
617
+ var self = this;
618
+ // Initializing promise
619
+ var deferred = q.defer();
620
+ // Validations
621
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
622
+ if (error) {
623
+ deferred.reject(error);
624
+ } else {
625
+ if (options && options.gradeformat_id) {
626
+ // Passed all validations, Contruct API url
627
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
628
+ self.config.AUTHEXTN_API_URLS.gradeformatClasses;
629
+
630
+ url = helpers.api.constructAPIUrl(url, {
631
+ orgid: self.orgId,
632
+ gradeformat_id: options.gradeformat_id
633
+ });
634
+
635
+ // Setup request with URL and Query Params
636
+ var params = {};
637
+ if (options.cursor) { params.cursor = options.cursor; }
638
+
639
+ var requestAPI = request.get(url).query(params);
640
+
641
+ // Setup traceid in request header
642
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
643
+
644
+ // Setup token in Authorization header
645
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
646
+
647
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
648
+ if (error) {
649
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
650
+ deferred.reject(error);
651
+ } else {
652
+ deferred.resolve(response.body);
653
+ }
654
+ });
655
+ } else {
656
+ error = {};
657
+ error.message = error.description = 'Mandatory params: gradeformat_id' +
658
+ ' not found in request options.';
659
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
660
+ deferred.reject(error);
661
+ }
662
+ }
663
+
664
+ return deferred.promise;
665
+ }
666
+
667
+ /**
668
+ * Wiki Link for SDK params
669
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#createuserassignedpathenrollmentsparams
670
+ */
671
+ function createUserAssignedPathEnrollments(options) {
672
+ var self = this;
673
+ // Initializing promise
674
+ var dfd = q.defer();
675
+
676
+ //Validations
677
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
678
+ if(error) {
679
+ dfd.reject(error);
680
+ } else {
681
+ if(options && options.classid && options.assignedpathid && options.body) {
682
+ // Passed all validations, Contruct API url
683
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
684
+ self.config.AUTHEXTN_API_URLS.userAssignedPaths;
685
+ url = helpers.api.constructAPIUrl(url, {
686
+ orgid: self.orgId,
687
+ classid: options.classid,
688
+ assignedpathid: options.assignedpathid,
689
+ });
690
+
691
+ var requestAPI = request.post(url)
692
+ .set('Content-Type', 'application/json')
693
+ .set('Accept', 'application/json')
694
+ .send(options.body);
695
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
696
+
697
+ //Setup token in Authorization header
698
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
699
+
700
+ requestAPI
701
+ .agent(keepaliveAgent)
702
+ .end(function(error, response) {
703
+ if(error) {
704
+ var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
705
+ dfd.reject(err);
706
+ }
707
+ else { dfd.resolve(response.body); }
708
+ });
709
+ } else {
710
+ var err = {};
711
+ err.message = err.description = 'Mandatory param: classid, assignedpathid, body' +
712
+ ' not found in request options.';
713
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
714
+ dfd.reject(err);
715
+ }
716
+ }
717
+ return dfd.promise;
718
+ }
719
+
720
+ /**
721
+ * Wiki Link for SDK params
722
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#deleteuserassignedpathenrollmentsparams
723
+ */
724
+ function deleteUserAssignedPathEnrollments(options) {
725
+ var self = this;
726
+ // Initializing promise
727
+ var dfd = q.defer();
728
+
729
+ //Validations
730
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
731
+ if(error) {
732
+ dfd.reject(error);
733
+ } else {
734
+ if(options && options.classid && options.assignedpathid && options.body) {
735
+ // Passed all validations, Contruct API url
736
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
737
+ self.config.AUTHEXTN_API_URLS.userAssignedPaths;
738
+ url = helpers.api.constructAPIUrl(url, {
739
+ orgid: self.orgId,
740
+ classid: options.classid,
741
+ assignedpathid: options.assignedpathid,
742
+ });
743
+
744
+ var requestAPI = request.delete(url)
745
+ .set('Content-Type', 'application/json')
746
+ .set('Accept', 'application/json')
747
+ .send(options.body);
748
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
749
+
750
+ //Setup token in Authorization header
751
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
752
+
753
+ requestAPI
754
+ .agent(keepaliveAgent)
755
+ .end(function(error, response) {
756
+ if(error) {
757
+ var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
758
+ dfd.reject(err);
759
+ }
760
+ else { dfd.resolve(response.body); }
761
+ });
762
+ } else {
763
+ var err = {};
764
+ err.message = err.description = 'Mandatory param: classid, assignedpathid, body' +
765
+ ' not found in request options.';
766
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
767
+ dfd.reject(err);
768
+ }
769
+ }
770
+ return dfd.promise;
771
+ }
772
+
773
+ /**
774
+ * Wiki Link for SDK params
775
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticularclassv2params
776
+ */
777
+ function getParticularClassV2(options) {
778
+ var self = this;
779
+ //Initializing promise
780
+ var deferred = q.defer();
781
+
782
+ //Validations
783
+ var error = helpers.validations.isAuthenticated(self.orgId, self.token);
784
+ if (error) {
785
+ deferred.reject(error);
786
+ } else {
787
+ if (options && options.classId) {
788
+ // Passed all validations, Contruct the API URL
789
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.particularClass;
790
+ url = helpers.api.constructAPIUrl(url, { orgId: self.orgId, classId: options.classId });
791
+
792
+ // Setup request with URL and Query Params
793
+ var params = { productDetails: options.productDetails, bundleDetails: options.bundleDetails };
794
+ var requestAPI = request.get(url).query(params);
795
+
796
+ // Setup 'traceid' in request header
797
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
798
+
799
+ // Setup 'token' in Authorization header
800
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
801
+
802
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
803
+ if (error) {
804
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
805
+ deferred.reject(error);
806
+ } else {
807
+ deferred.resolve(response.body);
808
+ }
809
+ });
810
+ } else {
811
+ error = {};
812
+ error.message = error.description = 'Mandatory field \'classId\' not found in request options.';
813
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
814
+ deferred.reject(error);
815
+ }
816
+ }
817
+
818
+ return deferred.promise;
819
+ }
820
+
821
+ /**
822
+ * Wiki Link for SDK params
823
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#createorgproductentitlementparams
824
+ */
825
+ function createOrgProductEntitlement(options) {
826
+ var self = this;
827
+ // Initializing promise
828
+ var dfd = q.defer();
829
+ if (!self.orgId) {
830
+ var err = {};
831
+ err.message = err.description = 'Mandatory param: orgid not found in options while ' +
832
+ 'initializing comprodls-sdk.';
833
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
834
+ dfd.reject(err);
835
+ } else {
836
+ if (options && options.productcode) {
837
+ // Passed all validations, Contruct API url
838
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
839
+ self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
840
+ url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
841
+
842
+ var requestAPI = request.post(url)
843
+ .set('Content-Type', 'application/json')
844
+ .set('Accept', 'application/json')
845
+ .send(options);
846
+
847
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
848
+
849
+ requestAPI
850
+ .agent(keepaliveAgent)
851
+ .end(function(error, response) {
852
+ if (error) {
853
+ var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
854
+ dfd.reject(err);
855
+ }
856
+ else { dfd.resolve(response.body); }
857
+ });
858
+ } else {
859
+ var err = {};
860
+ err.message = err.description = 'Mandatory param: productcode not found in request options.';
861
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
862
+ dfd.reject(err);
863
+ }
864
+ }
865
+ return dfd.promise;
866
+ }
867
+
868
+ /**
869
+ * Wiki Link for SDK params
870
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#updateorgproductentitlementparams
871
+ */
872
+ function updateOrgProductEntitlement(options) {
873
+ var self = this;
874
+ // Initializing promise
875
+ var dfd = q.defer();
876
+
877
+ if (!self.orgId) {
878
+ var err = {};
879
+ err.message = err.description = 'Mandatory param: orgid not found in options while ' +
880
+ 'initializing comprodls-sdk.';
881
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
882
+ dfd.reject(err);
883
+ } else {
884
+ if (options && options.productcode) {
885
+ // Passed all validations, Contruct API url
886
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
887
+ self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
888
+ url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
889
+
890
+ var requestAPI = request.put(url)
891
+ .set('Content-Type', 'application/json')
892
+ .set('Accept', 'application/json')
893
+ .send(options);
894
+
895
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
896
+
897
+ requestAPI
898
+ .agent(keepaliveAgent)
899
+ .end(function(error, response) {
900
+ if (error) {
901
+ var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
902
+ dfd.reject(err);
903
+ }
904
+ else { dfd.resolve(response.body); }
905
+ });
906
+ } else {
907
+ var err = {};
908
+ err.message = err.description = 'Mandatory param: productcode not found in request options.';
909
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
910
+ dfd.reject(err);
911
+ }
912
+ }
913
+
914
+ return dfd.promise;
915
+ }
916
+
917
+ /**
918
+ * Wiki Link for SDK params
919
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#deleteorgproductentitlementparams
920
+ */
921
+ function deleteOrgProductEntitlement(options) {
922
+ var self = this;
923
+
924
+ // Validate productcode
925
+ if (!(options && options.productcode)) {
926
+ var err = {};
927
+ err.message = err.description = 'Mandatory param: productcode not found in request options.';
928
+ return Promise.reject(new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err));
929
+ }
930
+
931
+ // Authenticate token
932
+ var error = helpers.validations.isAuthenticatedV2(self.orgId, self.token);
933
+ if (error) { return Promise.reject(error); }
934
+
935
+ // Construct API URL
936
+ var url = helpers.api.constructAPIUrl(
937
+ self.config.DEFAULT_HOSTS.AUTHEXTN + self.config.AUTHEXTN_API_URLS.orgProductEntitlement,
938
+ { orgid: self.orgId }
939
+ );
940
+
941
+ // Prepare request parameters & execute request
942
+ var reqOptions = {
943
+ params: options,
944
+ headers: { traceid: self.traceid, token: self.token }
945
+ };
946
+ return requestLayer.delete(url, reqOptions)
947
+ .then(function (response) {
948
+ return response.body;
949
+ })
950
+ .catch(function (err) {
951
+ throw new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
952
+ });
953
+ }
954
+
955
+ /**
956
+ * Wiki Link for SDK params
957
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getparticularorgproductentitlementparams
958
+ */
959
+ function getParticularOrgProductEntitlement(options) {
960
+ var self = this;
961
+ //Initializing promise
962
+ var deferred = q.defer();
963
+
964
+ if (options && options.productcode) {
965
+ // Passed all validations, Contruct the API URL
966
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
967
+ self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
968
+ url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
969
+
970
+ // Setup request with URL and Query Params
971
+ var params = { productcode: options.productcode };
972
+ var requestAPI = request.get(url).query(params);
973
+
974
+ // Setup 'traceid' in request header
975
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
976
+
977
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
978
+ if (error) {
979
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
980
+ deferred.reject(error);
981
+ } else {
982
+ deferred.resolve(response.body);
983
+ }
984
+ });
985
+ } else {
986
+ var error = {};
987
+ error.message = error.description = 'Mandatory field \'productcode\' not found '+
988
+ 'in request options.';
989
+ error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
990
+ deferred.reject(error);
991
+ }
992
+
993
+ return deferred.promise;
994
+ }
995
+
996
+ /**
997
+ * Wiki Link for SDK params
998
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/28_AUTHEXTN-Adapter#getallorgproductentitlementsparams
999
+ */
1000
+ function getAllOrgProductEntitlements(options) {
1001
+ var self = this;
1002
+ //Initializing promise
1003
+ var deferred = q.defer();
1004
+
1005
+ // Contruct the API URL
1006
+ var url = self.config.DEFAULT_HOSTS.AUTHEXTN +
1007
+ self.config.AUTHEXTN_API_URLS.orgProductEntitlement;
1008
+ url = helpers.api.constructAPIUrl(url, { orgid: self.orgId });
1009
+
1010
+ // Setup request with URL and Query Params
1011
+ var params = { productcode: options.productcode };
1012
+
1013
+ if (options.status) { params.status = options.status; }
1014
+ if (options.hasOwnProperty('expired')) { params.expired = options.expired; }
1015
+ if (options.cursor) { params.cursor = options.cursor; }
1016
+
1017
+ var requestAPI = request.get(url).query(params);
1018
+
1019
+ // Setup 'traceid' in request header
1020
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
1021
+
1022
+ requestAPI.agent(keepaliveAgent).end(function (error, response) {
1023
+ if (error) {
1024
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
1025
+ deferred.reject(error);
1026
+ } else {
1027
+ deferred.resolve(response.body);
1028
+ }
1029
+ });
1030
+
1031
+ return deferred.promise;
1032
+ }