comprodls-sdk 2.12.0 → 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 -11471
  5. package/dist/comprodls-sdk.min.js +14 -14
  6. package/grunt/publish.js +148 -148
  7. package/lib/comprodls.js +146 -146
  8. package/lib/config/index.js +337 -337
  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 -2541
  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 -279
  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,929 +1,976 @@
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 AUTH API Adaptor
23
- * Functions for calling AUTH API.
24
- ************************************************************/
25
-
26
- var q = require('q');
27
- var request = require('superagent');
28
-
29
- var helpers = require('../../helpers');
30
-
31
- var DLSError = helpers.errors.DLSError;
32
-
33
- /*********************************
34
- * Setting Up Module Entry Point
35
- **********************************/
36
- module.exports = spaces;
37
-
38
- //Auth Adaptor Contsructor
39
- function spaces(accountId) {
40
- this.accountId = accountId;
41
- return {
42
- getUserSpaces: getUserSpaces.bind(this),
43
- validateSpaceCode: validateSpaceCode.bind(this),
44
- validateClassCode: validateClassCode.bind(this),
45
- generateSpaceCode: generateSpaceCode.bind(this),
46
- changeSpaceCode: changeSpaceCode.bind(this),
47
- joinInstituteSpace: joinInstituteSpace.bind(this),
48
- provisionSpacesToStudent: provisionSpacesToStudent.bind(this),
49
- provisionSpacesToTeacher: provisionSpacesToTeacher.bind(this),
50
- provisionBulkSpaces: provisionBulkSpaces.bind(this),
51
- shadowProvision: shadowProvision.bind(this),
52
- entitleUserToProduct: entitleUserToProduct.bind(this),
53
- revokeMicroEntitlementOfAUser: revokeMicroEntitlementOfAUser.bind(this),
54
- microEntitleUserToProduct: microEntitleUserToProduct.bind(this),
55
- enrollUserInClass: enrollUserInClass.bind(this),
56
- getExtProduct: getExtProduct.bind(this),
57
- getSpaceDetails: getSpaceDetails.bind(this),
58
- updateUserInformation: updateUserInformation.bind(this),
59
- getInvitationsByEmail: getInvitationsByEmail.bind(this)
60
- };
61
- }
62
-
63
- /*options = {
64
- extuserid: 'string',
65
- spaceRole: 'string', //optional
66
- spaceType: 'string', //optional
67
- spaceOrgContext: 'string', //optional
68
- details: boolean, //optional
69
- cursor: 'string' //optional
70
- }*/
71
- function getUserSpaces(options) {
72
- var self = this;
73
- // Initializing promise
74
- var dfd = q.defer();
75
- // Validations
76
-
77
- if(options && options.extuserid) {
78
- // Passed all validations, Contruct API url
79
- var url = self.config.DEFAULT_HOSTS.AUTH +
80
- self.config.AUTH_API_URLS.getUserSpaces;
81
- url = helpers.api.constructAPIUrl(url, {
82
- accountid: self.accountId, extuserid: options.extuserid
83
- });
84
-
85
- var params = {};
86
- if(options.spaceRole) { params.spaceRole = options.spaceRole; }
87
- if(options.spaceType) { params.spaceType = options.spaceType; }
88
- if(options.spaceOrgContext) { params.spaceOrgContext = options.spaceOrgContext; }
89
- if(options.details) { params.details = options.details; }
90
- if(options.cursor) { params.cursor = options.cursor; }
91
-
92
- // Setup request with URL and Params
93
- var requestAPI = request.get(url).query(params);
94
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
95
-
96
- requestAPI.end(function(error, response) {
97
- if(error) {
98
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
99
- dfd.reject(error);
100
- }
101
- else { dfd.resolve(response.body); }
102
- });
103
- } else {
104
- var err = {};
105
- err.message = err.description = 'extuserid not found in request options.';
106
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
107
- dfd.reject(err);
108
- }
109
- return dfd.promise;
110
- }
111
-
112
- /*options = {
113
- spaceCodeBody : {
114
- space_code: 'string'
115
- }
116
- }*/
117
- function validateSpaceCode(options) {
118
- var self = this;
119
- // Initializing promise
120
- var dfd = q.defer();
121
-
122
- if(options && options.spaceCodeBody && options.spaceCodeBody.space_code) {
123
- // Passed all validations, Contruct API url
124
- var url = self.config.DEFAULT_HOSTS.AUTH +
125
- self.config.AUTH_API_URLS.validateSpaceCode;
126
- url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
127
-
128
- // Setup request with URL and Params
129
- var requestAPI = request.post(url)
130
- .set('Content-Type', 'application/json')
131
- .set('Accept', 'application/json')
132
- .send(options.spaceCodeBody);
133
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
134
-
135
- requestAPI.end(function(error, response) {
136
- if(error) {
137
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
138
- dfd.reject(error);
139
- }
140
- else { dfd.resolve(response.body); }
141
- });
142
- } else {
143
- var err = {};
144
- err.message = err.description = 'spaceCodeBody or space_code not found in request options.';
145
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
146
- dfd.reject(err);
147
- }
148
-
149
- return dfd.promise;
150
- }
151
-
152
- /*options = {
153
- classCodeBody : {
154
- class_code: 'string'
155
- },
156
- details: boolean // optional
157
- }*/
158
- function validateClassCode(options) {
159
- var self = this;
160
- // Initializing promise
161
- var dfd = q.defer();
162
-
163
- if(options && options.classCodeBody && options.classCodeBody.class_code) {
164
- // Passed all validations, Contruct API url
165
- var url = self.config.DEFAULT_HOSTS.AUTH +
166
- self.config.AUTH_API_URLS.validateClassCode;
167
- url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
168
-
169
- var queryParams = {};
170
- if (options.details) {
171
- queryParams.details = options.details;
172
- }
173
-
174
- // Setup request with URL and Params
175
- var requestAPI = request.post(url)
176
- .set('Content-Type', 'application/json')
177
- .set('Accept', 'application/json')
178
- .query(queryParams)
179
- .send(options.classCodeBody);
180
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
181
-
182
- requestAPI.end(function(error, response) {
183
- if(error) {
184
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
185
- dfd.reject(error);
186
- }
187
- else { dfd.resolve(response.body); }
188
- });
189
- } else {
190
- var err = {};
191
- err.message = err.description = 'classCodeBody or class_code not found in request options.';
192
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
193
- dfd.reject(err);
194
- }
195
-
196
- return dfd.promise;
197
- }
198
- /* options = {
199
- "ignore_words": ["string"] //optional, This is the array of all bad words to be ignored.
200
- }*/
201
- function generateSpaceCode(options) {
202
- var self = this;
203
-
204
- // Initializing promise
205
- var dfd = q.defer();
206
-
207
- // Passed all validations, Contruct API url
208
- var url = self.config.DEFAULT_HOSTS.AUTH +
209
- self.config.AUTH_API_URLS.generateSpaceCode;
210
- url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
211
-
212
- var bodyParams = {};
213
- if(options.ignore_words) { bodyParams.ignore_words = options.ignore_words }
214
- // Setup request with URL and Params
215
- var requestAPI = request.post(url)
216
- .set('Content-Type', 'application/json')
217
- .set('Accept', 'application/json')
218
- .send(bodyParams);
219
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
220
-
221
- requestAPI.end(function(error, response) {
222
- if(error) {
223
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
224
- dfd.reject(error);
225
- }
226
- else { dfd.resolve(response); }
227
- });
228
-
229
- return dfd.promise;
230
- }
231
-
232
- /* options = {
233
- "ext_user_id": "string", //mandatory, This is the actor to change the spacecode.
234
- "ignore_words": ["string"] //optional, This is the array of all bad words to be ignored.
235
- "spacecode": "string" //mandatory, This is the spacecode that needs to be changed.
236
- }*/
237
- function changeSpaceCode(options) {
238
- var self = this;
239
- // Initializing promise
240
- var dfd = q.defer();
241
-
242
- if(options && options.ext_user_id && options.spacecode) {
243
- // Passed all validations, Contruct API url
244
- var url = self.config.DEFAULT_HOSTS.AUTH +
245
- self.config.AUTH_API_URLS.changeSpaceCode;
246
- url = helpers.api.constructAPIUrl(url, { accountid : self.accountId, spacecode: options.spacecode });
247
- var bodyParams = { ext_user_id: options.ext_user_id };
248
- if(options.ignore_words) { bodyParams.ignore_words = options.ignore_words }
249
- // Setup request with URL and Params
250
- var requestAPI = request.put(url)
251
- .set('Content-Type', 'application/json')
252
- .set('Accept', 'application/json')
253
- .send(bodyParams);
254
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
255
-
256
- requestAPI.end(function(error, response) {
257
- if(error) {
258
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
259
- dfd.reject(error);
260
- }
261
- else { dfd.resolve(response); }
262
- });
263
- } else {
264
- var err = {};
265
- err.message = err.description = 'Mandatory parameter options, ext_user_id or spacecode, not found in request options.';
266
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
267
- dfd.reject(err);
268
- }
269
-
270
- return dfd.promise;
271
- }
272
-
273
- /*
274
- ext_user_id: 'string',
275
- ext_role: 'string',
276
- space_code: 'string',
277
- ext_email: 'string', //optional
278
- ext_first_name: 'string', //optional
279
- ext_last_name: 'string, //optional
280
- ref_id: 'string' //optional
281
- */
282
- function joinInstituteSpace(options) {
283
- var self = this;
284
- // Initializing promise
285
- var dfd = q.defer();
286
-
287
- if(options && options.ext_user_id &&
288
- options.ext_role && options.space_code)
289
- {
290
- // Passed all validations, Contruct API url
291
- var url = self.config.DEFAULT_HOSTS.AUTH +
292
- self.config.AUTH_API_URLS.joinInstituteSpace;
293
- url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
294
-
295
- // Setup request with URL and Params
296
- var requestAPI = request.post(url)
297
- .set('Content-Type', 'application/json')
298
- .set('Accept', 'application/json')
299
- .send(options);
300
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
301
-
302
- requestAPI.end(function(error, response) {
303
- if(error) {
304
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
305
- dfd.reject(error);
306
- }
307
- else { dfd.resolve(response.body); }
308
- });
309
- } else {
310
- var err = {};
311
- err.message = err.description = 'ext_user_id or ext_role or space_code not found in request options.';
312
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
313
- dfd.reject(err);
314
- }
315
-
316
- return dfd.promise;
317
- }
318
-
319
- /*options = {
320
- ext_user_id: 'string',
321
- ext_role: 'string',
322
- ext_first_name: 'string',
323
- ext_last_name: 'string',
324
- ext_email: 'string',
325
- ref_id: 'string', (optional)
326
- class_code: 'string' (optional)
327
- products: [{
328
- productcode: 'string',
329
- ext_product_id: 'string',
330
- ext_product_meta: {
331
- startdate: 'string',
332
- enddate: 'string',
333
- ...
334
- }
335
- }]
336
- }*/
337
- function provisionSpacesToStudent(options) {
338
- var self = this;
339
- // Initializing promise
340
- var dfd = q.defer();
341
- var err = {};
342
- if(options && options.ext_user_id && options.ext_role) {
343
-
344
- // Passed all validations, Contruct API url
345
- var url = self.config.DEFAULT_HOSTS.AUTH +
346
- self.config.AUTH_API_URLS.provisionSpacesToStudent;
347
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
348
-
349
- // Setup request with URL and Params
350
- var requestAPI = request.post(url)
351
- .set('Content-Type', 'application/json')
352
- .set('Accept', 'application/json')
353
- .send(options);
354
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
355
-
356
- requestAPI.end(function(error, response) {
357
- if(error) {
358
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
359
- dfd.reject(error);
360
- }
361
- else { dfd.resolve(response.body); }
362
- });
363
- }
364
- else {
365
- err.message = err.description = 'ext_user_id or ext_role not found in request options.';
366
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
367
- dfd.reject(err);
368
- }
369
-
370
- return dfd.promise;
371
- }
372
-
373
- /**
374
- * This function is used to provision spaces to a user with ext_role as teacher.
375
- * options = {
376
- * ext_user_id: "string",
377
- * ext_role: "string",
378
- * ext_first_name: "string",
379
- * ext_last_name: "string",
380
- * ext_email: "string",
381
- * ref_id: "string"
382
- * };
383
- */
384
- function provisionSpacesToTeacher(options) {
385
- var self = this;
386
- // Initializing promise
387
- var dfd = q.defer();
388
-
389
- if(options && options.ext_user_id && options.ext_role)
390
- {
391
- // Passed all validations, Contruct API url
392
- var url = self.config.DEFAULT_HOSTS.AUTH +
393
- self.config.AUTH_API_URLS.provisionSpacesToTeacher;
394
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
395
-
396
- // Setup request with URL and Params
397
- var requestAPI = request.post(url)
398
- .set('Content-Type', 'application/json')
399
- .set('Accept', 'application/json')
400
- .send(options);
401
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
402
-
403
- requestAPI.end(function(error, response) {
404
- if(error) {
405
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
406
- dfd.reject(error);
407
- }
408
- else { dfd.resolve(response.body); }
409
- });
410
- } else {
411
- var err = {};
412
- err.message = err.description = 'Mandatory parameters [rxt_user_id, ext_role] not found in request options.';
413
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
414
- dfd.reject(err);
415
- }
416
-
417
- return dfd.promise;
418
- }
419
-
420
- /**
421
- * options = {
422
- "space_title": "string", // mandatory
423
- "ext_data": {} //optional, external data(e.g. jobdata etc.)
424
- "users": [ // mandatory, min: 1, max: 200
425
- {
426
- "ext_user_id": "string", // mandatory (it must be unique within users array)
427
- "ext_parent_id": "string",
428
- "ext_username": "string",
429
- "ext_role": "student", // mandatory
430
- "ext_email": "string",
431
- "ext_first_name": "string", // mandatory
432
- "ext_last_name": "string", // mandatory
433
- "address": "string",
434
- "rowId": "string", // mandatory (it must be unique within users array)
435
- "classes": [ // optional, min: 1, max: 3
436
- {
437
- "classid": "string", // either of classid or class_code them must be
438
- "class_code": "string" // present, classid is preferred
439
- }
440
- ],
441
- "products": [ // optional, min: 1
442
- {
443
- "productcode": "string", // mandatory
444
- "ext_product_meta": {
445
- "startdate": "epoch",
446
- "enddate": "epoch" // mandatory
447
- }
448
- "ext_data" : {} // optional, external data (e.g., ref_id, ...)
449
- }
450
- ]
451
- }
452
- ]
453
- }
454
- *
455
- */
456
- function provisionBulkSpaces(options) {
457
- var self = this;
458
- // Initializing promise
459
- var dfd = q.defer();
460
- // Validations
461
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
462
- if(err) { dfd.reject(err); }
463
- else {
464
- if(options && options.users && options.space_title) {
465
- // Passed all validations, Contruct API url
466
- var url = self.config.DEFAULT_HOSTS.AUTH +
467
- self.config.AUTH_API_URLS.provisionBulkSpaces;
468
- url = helpers.api.constructAPIUrl(url, { orgId : self.orgId });
469
-
470
- // Setup request with URL and Params
471
- var requestAPI = request.post(url)
472
- .set('Content-Type', 'application/json')
473
- .set('Accept', 'application/json')
474
- .send(options);
475
-
476
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
477
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
478
-
479
- requestAPI.end(function(error, response) {
480
- if(error) {
481
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
482
- dfd.reject(err);
483
- }
484
- else { dfd.resolve(response.body); }
485
- });
486
- }
487
- else {
488
- err = {};
489
- err.message = err.description = 'Mandatory parameters: space_title or users not found in request options.';
490
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
491
- dfd.reject(err);
492
- }
493
- }
494
-
495
- return dfd.promise;
496
- }
497
-
498
- /**
499
- * options = {
500
- * ext_user_id: 'string', // mandatory
501
- * "ext_role": "string", // mandatory
502
- * "ext_first_name": "string",
503
- * "ext_last_name": "string",
504
- * "ext_email": "string",
505
- * "address": {
506
- * "country": "string"
507
- * },
508
- * "ref_id": "string",
509
- * "ext_classid" : "string",
510
- * "ext_class_meta" :
511
- * {
512
- * "description": "string",
513
- * "title": "string", // mandatory
514
- * "startdate": <epoch>, // mandatory
515
- * "enddate": <epoch> // mandatory
516
- * }
517
- * }
518
- **/
519
- function shadowProvision(options) {
520
- var self = this;
521
- //Initializing promise
522
- var dfd = q.defer(), err = {};
523
- //Validations
524
- if (options && options.ext_user_id && options.ext_role) {
525
- //Passed all validations, Contruct API url
526
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.shadowProvision;
527
- url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
528
-
529
- // Setup request with URL and Params
530
- var requestAPI = request.post(url)
531
- .set('Content-Type', 'application/json')
532
- .set('Accept', 'application/json')
533
- .send(options);
534
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
535
-
536
- requestAPI.end(function (err, response) {
537
- if (err) {
538
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
539
- dfd.reject(err);
540
- }
541
- else { dfd.resolve(response.body); }
542
- });
543
- }
544
- else {
545
- err.message = err.description = 'Mandatory parameters: ext_user_id or ext_role not ' +
546
- 'found in request options.';
547
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
548
- dfd.reject(err);
549
- }
550
- return dfd.promise;
551
- }
552
-
553
- /*options = {
554
- ext_user_id: 'string',
555
- ext_role: 'string',
556
- ref_id: 'string', (optional)
557
- productcode: 'string',
558
- ext_product_id: 'string',
559
- ext_product_meta: {
560
- startdate: 'string',
561
- enddate: 'string',
562
- ...
563
- }
564
- }*/
565
- function entitleUserToProduct(options) {
566
- var self = this;
567
- // Initializing promise
568
- var dfd = q.defer();
569
-
570
- if(options && options.ext_user_id &&
571
- options.ext_role && (options.productcode || options.ext_product_id))
572
- {
573
- // Passed all validations, Contruct API url
574
- var url = self.config.DEFAULT_HOSTS.AUTH +
575
- self.config.AUTH_API_URLS.entitleUserToProduct;
576
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
577
-
578
- // Setup request with URL and Params
579
- var requestAPI = request.post(url)
580
- .set('Content-Type', 'application/json')
581
- .set('Accept', 'application/json')
582
- .send(options);
583
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
584
-
585
- requestAPI.end(function(error, response) {
586
- if(error) {
587
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
588
- dfd.reject(error);
589
- }
590
- else { dfd.resolve(response.body); }
591
- });
592
- } else {
593
- var err = {};
594
- err.description = 'Missing mandatory keys in request options. \'ext_user_id\', \'ext_role\' and ' +
595
- 'either of \'ext_product_id\' or \'productcode\' must be present.'
596
- err.message = err.description;
597
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
598
- dfd.reject(err);
599
- }
600
-
601
- return dfd.promise;
602
- }
603
-
604
- /* This function calls the ComproDLS API to micro entitle user to a product.
605
- options = {
606
- "ext_user_id": "string", // Mandatory
607
- "feature_key": "string", // Mandatory
608
- "feature_id": "string", // Mandatory
609
- "context": "string", // Mandatory
610
- "data": {}, // Optional
611
- "productcode": "string", // one of productcode and ext_product_id is mandatory
612
- "ext_product_id": "string",
613
- "ext_entitlement_meta": { //Optional
614
- "startdate": "epoch",
615
- "enddate": "epoch" //mandatory, if ext_entitlement_meta provided.
616
- }
617
- }*/
618
- function microEntitleUserToProduct(options) {
619
- var self = this;
620
- // Initializing promise
621
- var dfd = q.defer();
622
- var bValidOptions = true;
623
- var err = {
624
- description: '',
625
- message: ''
626
- };
627
-
628
- if (!(options && options.ext_user_id && options.context && options.feature_key &&
629
- options.feature_id)) {
630
- bValidOptions = false;
631
- err.description = 'ext_user_id or context or feature_key or feature_id ' +
632
- 'not found in request options. ';
633
- }
634
-
635
- if (bValidOptions && (options.productcode || options.ext_product_id)) {
636
- // Passed all validations, Contruct API url
637
- var url = self.config.DEFAULT_HOSTS.AUTH +
638
- self.config.AUTH_API_URLS.microEntitleUserToProduct;
639
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
640
-
641
- // Setup request with URL and Params
642
- var requestAPI = request.post(url)
643
- .set('Content-Type', 'application/json')
644
- .set('Accept', 'application/json')
645
- .send(options);
646
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
647
-
648
- requestAPI.end(function(error, response) {
649
- if(error) {
650
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
651
- dfd.reject(error);
652
- }
653
- else { dfd.resolve(response.body); }
654
- });
655
- } else {
656
- if(!(options.productcode || options.ext_product_id)) {
657
- err.description += 'Either of ext_product_id or productcode must be ' +
658
- 'present in request options.';
659
- }
660
- err.message = err.description;
661
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
662
- dfd.reject(err);
663
- }
664
-
665
- return dfd.promise;
666
- }
667
-
668
- /* This function calls the ComproDLS API to revoke micro entitlement of a user.
669
- options = {
670
- "ext_user_id": "string", // Mandatory
671
- "feature_key": "string", // Mandatory
672
- "context": "string", // Mandatory
673
- "productcode": "string", // one of productcode and ext_product_id is mandatory
674
- "ext_product_id": "string",
675
- }*/
676
- function revokeMicroEntitlementOfAUser(options) {
677
- var self = this;
678
- // Initializing promise
679
- var dfd = q.defer();
680
- var err = {
681
- description: '',
682
- message: ''
683
- };
684
-
685
- if((options && options.ext_user_id && options.context && options.feature_key &&
686
- (options.productcode || options.ext_product_id))) {
687
- // Passed all validations, Contruct API url
688
- var url = self.config.DEFAULT_HOSTS.AUTH +
689
- self.config.AUTH_API_URLS.microEntitleUserToProduct;
690
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
691
-
692
- // Setup request with URL and Params
693
- var requestAPI = request.delete(url)
694
- .set('Content-Type', 'application/json')
695
- .set('Accept', 'application/json')
696
- .send(options);
697
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
698
-
699
- requestAPI.end(function(error, response) {
700
- if(error) {
701
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
702
- dfd.reject(error);
703
- }
704
- else { dfd.resolve(response.body); }
705
- });
706
- }
707
- else {
708
- err.description = 'ext_user_id or context or feature_key not found or is empty in request options. ' +
709
- 'Either productcode or ext_product_id must be provided.';
710
- err.message = err.description;
711
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
712
- dfd.reject(err);
713
- }
714
-
715
- return dfd.promise;
716
- }
717
-
718
- /*options = {
719
- ext_product_id: 'string'
720
- }*/
721
- function getExtProduct(options) {
722
- var self = this;
723
- // Initializing promise
724
- var dfd = q.defer();
725
-
726
- if(options && options.ext_product_id)
727
- {
728
- // Passed all validations, Contruct API url
729
- var url = self.config.DEFAULT_HOSTS.AUTH +
730
- self.config.AUTH_API_URLS.getExtProductAPI;
731
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, extProductId: options.ext_product_id});
732
-
733
- // Setup request with URL and Params
734
- var requestAPI = request.get(url);
735
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
736
-
737
- requestAPI.end(function(error, response) {
738
- if(error) {
739
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
740
- dfd.reject(error);
741
- }
742
- else { dfd.resolve(response.body); }
743
- });
744
- } else {
745
- var err = {};
746
- err.message = err.description = 'ext_product_id not found in request options.';
747
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
748
- dfd.reject(err);
749
- }
750
-
751
- return dfd.promise;
752
- }
753
-
754
- /*options = {
755
- spacekey: 'string'
756
- }*/
757
- function getSpaceDetails(options) {
758
- var self = this;
759
- // Initializing promise
760
- var dfd = q.defer();
761
-
762
- if(options && options.spacekey) {
763
- // Passed all validations, Contruct API url
764
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getSpaceDetails;
765
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, spacekey: options.spacekey});
766
-
767
- var params = { orgid: self.orgId };
768
-
769
- // Setup request with URL and Params
770
- var requestAPI = request.get(url).query(params);
771
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
772
-
773
- // Setup token in Authorization header
774
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
775
-
776
- requestAPI.end(function(error, response) {
777
- if(error) {
778
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
779
- dfd.reject(error);
780
- }
781
- else { dfd.resolve(response.body); }
782
- });
783
- } else {
784
- var err = {};
785
- err.message = err.description = 'spacekey not found in request options.';
786
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
787
- dfd.reject(err);
788
- }
789
-
790
- return dfd.promise;
791
- }
792
-
793
- /*options = {
794
- ext_user_id: 'string',
795
- ext_role: 'string',
796
- ext_first_name: 'string',
797
- ext_last_name: 'string',
798
- ext_email: 'string',
799
- ref_id: 'string', (optional)
800
- class_code: 'string'
801
- }*/
802
- function enrollUserInClass(options) {
803
- var self = this;
804
- // Initializing promise
805
- var dfd = q.defer();
806
-
807
- if(options && options.ext_user_id &&
808
- options.ext_role && options.class_code)
809
- {
810
- // Passed all validations, Contruct API url
811
- var url = self.config.DEFAULT_HOSTS.AUTH +
812
- self.config.AUTH_API_URLS.enrollUserInClass;
813
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
814
-
815
- // Setup request with URL and Params
816
- var requestAPI = request.post(url)
817
- .set('Content-Type', 'application/json')
818
- .set('Accept', 'application/json')
819
- .send(options);
820
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
821
-
822
- requestAPI.end(function(error, response) {
823
- if(error) {
824
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
825
- dfd.reject(error);
826
- }
827
- else { dfd.resolve(response.body); }
828
- });
829
- } else {
830
- var err = {};
831
- err.message = err.description = 'ext_user_id or ext_role or class_code not found in request options.';
832
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
833
- dfd.reject(err);
834
- }
835
-
836
- return dfd.promise;
837
- }
838
-
839
- /**
840
- * This function calls the ComproDLS API to update user information.
841
- * options = {
842
- * "ext_user_id": "string",
843
- * "ref_id": "string", // optional
844
- * "ext_email": "string", // optional
845
- * "ext_first_name": "string", // optional
846
- * "ext_last_name": "string" // optional
847
- * };
848
- */
849
- function updateUserInformation(options) {
850
- var self = this;
851
- // Initializing promise
852
- var dfd = q.defer(), err = {};
853
-
854
- if(options && options.ext_user_id)
855
- {
856
- // Passed all validations, Contruct API url
857
- var url = self.config.DEFAULT_HOSTS.AUTH +
858
- self.config.AUTH_API_URLS.updateUserInformation;
859
- url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
860
- var bodyParams = {
861
- ext_user_id: options.ext_user_id
862
- };
863
- if(options.ref_id) { bodyParams.ref_id = options.ref_id; }
864
- if(options.ext_email) { bodyParams.ext_email = options.ext_email; }
865
- if(options.ext_first_name) { bodyParams.ext_first_name = options.ext_first_name; }
866
- if(options.ext_last_name) { bodyParams.ext_last_name = options.ext_last_name; }
867
- if(options.address) { bodyParams.address = options.address; }
868
- // Setup request with URL and Params
869
- var requestAPI = request.put(url)
870
- .set('Content-Type', 'application/json')
871
- .set('Accept', 'application/json')
872
- .send(bodyParams);
873
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
874
-
875
- requestAPI.end(function(error, response) {
876
- if(error) {
877
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
878
- dfd.reject(error);
879
- }
880
- else { dfd.resolve(response.body); }
881
- });
882
- } else {
883
- err.message = err.description = 'Mandatory parameters not found in request options:' +
884
- ' ["ext_user_id"]';
885
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
886
- dfd.reject(err);
887
- }
888
-
889
- return dfd.promise;
890
- }
891
-
892
- /* options = {
893
- "email": "string", // required
894
- "status " : "string", // optional
895
- };
896
- */
897
- function getInvitationsByEmail(options) {
898
- var self = this;
899
- // Initializing promise
900
- var dfd = q.defer();
901
- var err = {};
902
- if (options && options.email) {
903
-
904
- // Passed all validations, Contruct API url
905
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getInvitationsByEmail;
906
- url = helpers.api.constructAPIUrl(url, { accountid: self.accountId });
907
-
908
- var queryParam = { email: options.email };
909
- if (options.status) { queryParam.status = options.status; }
910
-
911
- // Setup request with URL and Params
912
- var requestAPI = request.get(url).query(queryParam);
913
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
914
-
915
- requestAPI.end(function (error, response) {
916
- if (error) {
917
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
918
- dfd.reject(err);
919
- }
920
- else { dfd.resolve(response.body); }
921
- });
922
- }
923
- else {
924
- err.message = err.description = 'email not found in request options.';
925
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
926
- dfd.reject(err);
927
- }
928
- return dfd.promise;
929
- }
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 AUTH API Adaptor
23
+ * Functions for calling AUTH API.
24
+ ************************************************************/
25
+
26
+ var q = require('q');
27
+ var request = require('superagent');
28
+
29
+ var helpers = require('../../helpers');
30
+
31
+ var DLSError = helpers.errors.DLSError;
32
+
33
+ /*********************************
34
+ * Setting Up Module Entry Point
35
+ **********************************/
36
+ module.exports = spaces;
37
+
38
+ //Auth Adaptor Contsructor
39
+ function spaces(accountId) {
40
+ this.accountId = accountId;
41
+ return {
42
+ getUserSpaces: getUserSpaces.bind(this),
43
+ validateSpaceCode: validateSpaceCode.bind(this),
44
+ validateClassCode: validateClassCode.bind(this),
45
+ generateSpaceCode: generateSpaceCode.bind(this),
46
+ changeSpaceCode: changeSpaceCode.bind(this),
47
+ joinInstituteSpace: joinInstituteSpace.bind(this),
48
+ provisionSpacesToStudent: provisionSpacesToStudent.bind(this),
49
+ provisionSpacesToTeacher: provisionSpacesToTeacher.bind(this),
50
+ provisionBulkSpaces: provisionBulkSpaces.bind(this),
51
+ shadowProvision: shadowProvision.bind(this),
52
+ entitleUserToProduct: entitleUserToProduct.bind(this),
53
+ unentitleUserToProduct: unentitleUserToProduct.bind(this),
54
+ revokeMicroEntitlementOfAUser: revokeMicroEntitlementOfAUser.bind(this),
55
+ microEntitleUserToProduct: microEntitleUserToProduct.bind(this),
56
+ enrollUserInClass: enrollUserInClass.bind(this),
57
+ getExtProduct: getExtProduct.bind(this),
58
+ getSpaceDetails: getSpaceDetails.bind(this),
59
+ updateUserInformation: updateUserInformation.bind(this),
60
+ getInvitationsByEmail: getInvitationsByEmail.bind(this)
61
+ };
62
+ }
63
+
64
+ /*options = {
65
+ extuserid: 'string',
66
+ spaceRole: 'string', //optional
67
+ spaceType: 'string', //optional
68
+ spaceOrgContext: 'string', //optional
69
+ details: boolean, //optional
70
+ cursor: 'string' //optional
71
+ }*/
72
+ function getUserSpaces(options) {
73
+ var self = this;
74
+ // Initializing promise
75
+ var dfd = q.defer();
76
+ // Validations
77
+
78
+ if(options && options.extuserid) {
79
+ // Passed all validations, Contruct API url
80
+ var url = self.config.DEFAULT_HOSTS.AUTH +
81
+ self.config.AUTH_API_URLS.getUserSpaces;
82
+ url = helpers.api.constructAPIUrl(url, {
83
+ accountid: self.accountId, extuserid: options.extuserid
84
+ });
85
+
86
+ var params = {};
87
+ if(options.spaceRole) { params.spaceRole = options.spaceRole; }
88
+ if(options.spaceType) { params.spaceType = options.spaceType; }
89
+ if(options.spaceOrgContext) { params.spaceOrgContext = options.spaceOrgContext; }
90
+ if(options.details) { params.details = options.details; }
91
+ if(options.cursor) { params.cursor = options.cursor; }
92
+
93
+ // Setup request with URL and Params
94
+ var requestAPI = request.get(url).query(params);
95
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
96
+
97
+ requestAPI.end(function(error, response) {
98
+ if(error) {
99
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
100
+ dfd.reject(error);
101
+ }
102
+ else { dfd.resolve(response.body); }
103
+ });
104
+ } else {
105
+ var err = {};
106
+ err.message = err.description = 'extuserid not found in request options.';
107
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
108
+ dfd.reject(err);
109
+ }
110
+ return dfd.promise;
111
+ }
112
+
113
+ /*options = {
114
+ spaceCodeBody : {
115
+ space_code: 'string'
116
+ }
117
+ }*/
118
+ function validateSpaceCode(options) {
119
+ var self = this;
120
+ // Initializing promise
121
+ var dfd = q.defer();
122
+
123
+ if(options && options.spaceCodeBody && options.spaceCodeBody.space_code) {
124
+ // Passed all validations, Contruct API url
125
+ var url = self.config.DEFAULT_HOSTS.AUTH +
126
+ self.config.AUTH_API_URLS.validateSpaceCode;
127
+ url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
128
+
129
+ // Setup request with URL and Params
130
+ var requestAPI = request.post(url)
131
+ .set('Content-Type', 'application/json')
132
+ .set('Accept', 'application/json')
133
+ .send(options.spaceCodeBody);
134
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
135
+
136
+ requestAPI.end(function(error, response) {
137
+ if(error) {
138
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
139
+ dfd.reject(error);
140
+ }
141
+ else { dfd.resolve(response.body); }
142
+ });
143
+ } else {
144
+ var err = {};
145
+ err.message = err.description = 'spaceCodeBody or space_code not found in request options.';
146
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
147
+ dfd.reject(err);
148
+ }
149
+
150
+ return dfd.promise;
151
+ }
152
+
153
+ /*options = {
154
+ classCodeBody : {
155
+ class_code: 'string'
156
+ },
157
+ details: boolean // optional
158
+ }*/
159
+ function validateClassCode(options) {
160
+ var self = this;
161
+ // Initializing promise
162
+ var dfd = q.defer();
163
+
164
+ if(options && options.classCodeBody && options.classCodeBody.class_code) {
165
+ // Passed all validations, Contruct API url
166
+ var url = self.config.DEFAULT_HOSTS.AUTH +
167
+ self.config.AUTH_API_URLS.validateClassCode;
168
+ url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
169
+
170
+ var queryParams = {};
171
+ if (options.details) {
172
+ queryParams.details = options.details;
173
+ }
174
+
175
+ // Setup request with URL and Params
176
+ var requestAPI = request.post(url)
177
+ .set('Content-Type', 'application/json')
178
+ .set('Accept', 'application/json')
179
+ .query(queryParams)
180
+ .send(options.classCodeBody);
181
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
182
+
183
+ requestAPI.end(function(error, response) {
184
+ if(error) {
185
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
186
+ dfd.reject(error);
187
+ }
188
+ else { dfd.resolve(response.body); }
189
+ });
190
+ } else {
191
+ var err = {};
192
+ err.message = err.description = 'classCodeBody or class_code not found in request options.';
193
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
194
+ dfd.reject(err);
195
+ }
196
+
197
+ return dfd.promise;
198
+ }
199
+ /* options = {
200
+ "ignore_words": ["string"] //optional, This is the array of all bad words to be ignored.
201
+ }*/
202
+ function generateSpaceCode(options) {
203
+ var self = this;
204
+
205
+ // Initializing promise
206
+ var dfd = q.defer();
207
+
208
+ // Passed all validations, Contruct API url
209
+ var url = self.config.DEFAULT_HOSTS.AUTH +
210
+ self.config.AUTH_API_URLS.generateSpaceCode;
211
+ url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
212
+
213
+ var bodyParams = {};
214
+ if(options.ignore_words) { bodyParams.ignore_words = options.ignore_words }
215
+ // Setup request with URL and Params
216
+ var requestAPI = request.post(url)
217
+ .set('Content-Type', 'application/json')
218
+ .set('Accept', 'application/json')
219
+ .send(bodyParams);
220
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
221
+
222
+ requestAPI.end(function(error, response) {
223
+ if(error) {
224
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
225
+ dfd.reject(error);
226
+ }
227
+ else { dfd.resolve(response); }
228
+ });
229
+
230
+ return dfd.promise;
231
+ }
232
+
233
+ /* options = {
234
+ "ext_user_id": "string", //mandatory, This is the actor to change the spacecode.
235
+ "ignore_words": ["string"] //optional, This is the array of all bad words to be ignored.
236
+ "spacecode": "string" //mandatory, This is the spacecode that needs to be changed.
237
+ }*/
238
+ function changeSpaceCode(options) {
239
+ var self = this;
240
+ // Initializing promise
241
+ var dfd = q.defer();
242
+
243
+ if(options && options.ext_user_id && options.spacecode) {
244
+ // Passed all validations, Contruct API url
245
+ var url = self.config.DEFAULT_HOSTS.AUTH +
246
+ self.config.AUTH_API_URLS.changeSpaceCode;
247
+ url = helpers.api.constructAPIUrl(url, { accountid : self.accountId, spacecode: options.spacecode });
248
+ var bodyParams = { ext_user_id: options.ext_user_id };
249
+ if(options.ignore_words) { bodyParams.ignore_words = options.ignore_words }
250
+ // Setup request with URL and Params
251
+ var requestAPI = request.put(url)
252
+ .set('Content-Type', 'application/json')
253
+ .set('Accept', 'application/json')
254
+ .send(bodyParams);
255
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
256
+
257
+ requestAPI.end(function(error, response) {
258
+ if(error) {
259
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
260
+ dfd.reject(error);
261
+ }
262
+ else { dfd.resolve(response); }
263
+ });
264
+ } else {
265
+ var err = {};
266
+ err.message = err.description = 'Mandatory parameter options, ext_user_id or spacecode, not found in request options.';
267
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
268
+ dfd.reject(err);
269
+ }
270
+
271
+ return dfd.promise;
272
+ }
273
+
274
+ /*
275
+ ext_user_id: 'string',
276
+ ext_role: 'string',
277
+ space_code: 'string',
278
+ ext_email: 'string', //optional
279
+ ext_first_name: 'string', //optional
280
+ ext_last_name: 'string, //optional
281
+ ref_id: 'string' //optional
282
+ */
283
+ function joinInstituteSpace(options) {
284
+ var self = this;
285
+ // Initializing promise
286
+ var dfd = q.defer();
287
+
288
+ if(options && options.ext_user_id &&
289
+ options.ext_role && options.space_code)
290
+ {
291
+ // Passed all validations, Contruct API url
292
+ var url = self.config.DEFAULT_HOSTS.AUTH +
293
+ self.config.AUTH_API_URLS.joinInstituteSpace;
294
+ url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
295
+
296
+ // Setup request with URL and Params
297
+ var requestAPI = request.post(url)
298
+ .set('Content-Type', 'application/json')
299
+ .set('Accept', 'application/json')
300
+ .send(options);
301
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
302
+
303
+ requestAPI.end(function(error, response) {
304
+ if(error) {
305
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
306
+ dfd.reject(error);
307
+ }
308
+ else { dfd.resolve(response.body); }
309
+ });
310
+ } else {
311
+ var err = {};
312
+ err.message = err.description = 'ext_user_id or ext_role or space_code not found in request options.';
313
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
314
+ dfd.reject(err);
315
+ }
316
+
317
+ return dfd.promise;
318
+ }
319
+
320
+ /*options = {
321
+ ext_user_id: 'string',
322
+ ext_role: 'string',
323
+ ext_first_name: 'string',
324
+ ext_last_name: 'string',
325
+ ext_email: 'string',
326
+ ref_id: 'string', (optional)
327
+ class_code: 'string' (optional)
328
+ products: [{
329
+ productcode: 'string',
330
+ ext_product_id: 'string',
331
+ ext_product_meta: {
332
+ startdate: 'string',
333
+ enddate: 'string',
334
+ ...
335
+ }
336
+ }]
337
+ }*/
338
+ function provisionSpacesToStudent(options) {
339
+ var self = this;
340
+ // Initializing promise
341
+ var dfd = q.defer();
342
+ var err = {};
343
+ if(options && options.ext_user_id && options.ext_role) {
344
+
345
+ // Passed all validations, Contruct API url
346
+ var url = self.config.DEFAULT_HOSTS.AUTH +
347
+ self.config.AUTH_API_URLS.provisionSpacesToStudent;
348
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
349
+
350
+ // Setup request with URL and Params
351
+ var requestAPI = request.post(url)
352
+ .set('Content-Type', 'application/json')
353
+ .set('Accept', 'application/json')
354
+ .send(options);
355
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
356
+
357
+ requestAPI.end(function(error, response) {
358
+ if(error) {
359
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
360
+ dfd.reject(error);
361
+ }
362
+ else { dfd.resolve(response.body); }
363
+ });
364
+ }
365
+ else {
366
+ err.message = err.description = 'ext_user_id or ext_role not found in request options.';
367
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
368
+ dfd.reject(err);
369
+ }
370
+
371
+ return dfd.promise;
372
+ }
373
+
374
+ /**
375
+ * This function is used to provision spaces to a user with ext_role as teacher.
376
+ * options = {
377
+ * ext_user_id: "string",
378
+ * ext_role: "string",
379
+ * ext_first_name: "string",
380
+ * ext_last_name: "string",
381
+ * ext_email: "string",
382
+ * ref_id: "string"
383
+ * };
384
+ */
385
+ function provisionSpacesToTeacher(options) {
386
+ var self = this;
387
+ // Initializing promise
388
+ var dfd = q.defer();
389
+
390
+ if(options && options.ext_user_id && options.ext_role)
391
+ {
392
+ // Passed all validations, Contruct API url
393
+ var url = self.config.DEFAULT_HOSTS.AUTH +
394
+ self.config.AUTH_API_URLS.provisionSpacesToTeacher;
395
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
396
+
397
+ // Setup request with URL and Params
398
+ var requestAPI = request.post(url)
399
+ .set('Content-Type', 'application/json')
400
+ .set('Accept', 'application/json')
401
+ .send(options);
402
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
403
+
404
+ requestAPI.end(function(error, response) {
405
+ if(error) {
406
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
407
+ dfd.reject(error);
408
+ }
409
+ else { dfd.resolve(response.body); }
410
+ });
411
+ } else {
412
+ var err = {};
413
+ err.message = err.description = 'Mandatory parameters [rxt_user_id, ext_role] not found in request options.';
414
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
415
+ dfd.reject(err);
416
+ }
417
+
418
+ return dfd.promise;
419
+ }
420
+
421
+ /**
422
+ * options = {
423
+ "space_title": "string", // mandatory
424
+ "ext_data": {} //optional, external data(e.g. jobdata etc.)
425
+ "users": [ // mandatory, min: 1, max: 200
426
+ {
427
+ "ext_user_id": "string", // mandatory (it must be unique within users array)
428
+ "ext_parent_id": "string",
429
+ "ext_username": "string",
430
+ "ext_role": "student", // mandatory
431
+ "ext_email": "string",
432
+ "ext_first_name": "string", // mandatory
433
+ "ext_last_name": "string", // mandatory
434
+ "address": "string",
435
+ "rowId": "string", // mandatory (it must be unique within users array)
436
+ "classes": [ // optional, min: 1, max: 3
437
+ {
438
+ "classid": "string", // either of classid or class_code them must be
439
+ "class_code": "string" // present, classid is preferred
440
+ }
441
+ ],
442
+ "products": [ // optional, min: 1
443
+ {
444
+ "productcode": "string", // mandatory
445
+ "ext_product_meta": {
446
+ "startdate": "epoch",
447
+ "enddate": "epoch" // mandatory
448
+ }
449
+ "ext_data" : {} // optional, external data (e.g., ref_id, ...)
450
+ }
451
+ ]
452
+ }
453
+ ]
454
+ }
455
+ *
456
+ */
457
+ function provisionBulkSpaces(options) {
458
+ var self = this;
459
+ // Initializing promise
460
+ var dfd = q.defer();
461
+ // Validations
462
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
463
+ if(err) { dfd.reject(err); }
464
+ else {
465
+ if(options && options.users && options.space_title) {
466
+ // Passed all validations, Contruct API url
467
+ var url = self.config.DEFAULT_HOSTS.AUTH +
468
+ self.config.AUTH_API_URLS.provisionBulkSpaces;
469
+ url = helpers.api.constructAPIUrl(url, { orgId : self.orgId });
470
+
471
+ // Setup request with URL and Params
472
+ var requestAPI = request.post(url)
473
+ .set('Content-Type', 'application/json')
474
+ .set('Accept', 'application/json')
475
+ .send(options);
476
+
477
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
478
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
479
+
480
+ requestAPI.end(function(error, response) {
481
+ if(error) {
482
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
483
+ dfd.reject(err);
484
+ }
485
+ else { dfd.resolve(response.body); }
486
+ });
487
+ }
488
+ else {
489
+ err = {};
490
+ err.message = err.description = 'Mandatory parameters: space_title or users not found in request options.';
491
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
492
+ dfd.reject(err);
493
+ }
494
+ }
495
+
496
+ return dfd.promise;
497
+ }
498
+
499
+ /**
500
+ * options = {
501
+ * ext_user_id: 'string', // mandatory
502
+ * "ext_role": "string", // mandatory
503
+ * "ext_first_name": "string",
504
+ * "ext_last_name": "string",
505
+ * "ext_email": "string",
506
+ * "address": {
507
+ * "country": "string"
508
+ * },
509
+ * "ref_id": "string",
510
+ * "ext_classid" : "string",
511
+ * "ext_class_meta" :
512
+ * {
513
+ * "description": "string",
514
+ * "title": "string", // mandatory
515
+ * "startdate": <epoch>, // mandatory
516
+ * "enddate": <epoch> // mandatory
517
+ * }
518
+ * }
519
+ **/
520
+ function shadowProvision(options) {
521
+ var self = this;
522
+ //Initializing promise
523
+ var dfd = q.defer(), err = {};
524
+ //Validations
525
+ if (options && options.ext_user_id && options.ext_role) {
526
+ //Passed all validations, Contruct API url
527
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.shadowProvision;
528
+ url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
529
+
530
+ // Setup request with URL and Params
531
+ var requestAPI = request.post(url)
532
+ .set('Content-Type', 'application/json')
533
+ .set('Accept', 'application/json')
534
+ .send(options);
535
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
536
+
537
+ requestAPI.end(function (err, response) {
538
+ if (err) {
539
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
540
+ dfd.reject(err);
541
+ }
542
+ else { dfd.resolve(response.body); }
543
+ });
544
+ }
545
+ else {
546
+ err.message = err.description = 'Mandatory parameters: ext_user_id or ext_role not ' +
547
+ 'found in request options.';
548
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
549
+ dfd.reject(err);
550
+ }
551
+ return dfd.promise;
552
+ }
553
+
554
+ /*options = {
555
+ ext_user_id: 'string',
556
+ ext_role: 'string',
557
+ ref_id: 'string', (optional)
558
+ productcode: 'string',
559
+ ext_product_id: 'string',
560
+ ext_product_meta: {
561
+ startdate: 'string',
562
+ enddate: 'string',
563
+ ...
564
+ }
565
+ }*/
566
+ function entitleUserToProduct(options) {
567
+ var self = this;
568
+ // Initializing promise
569
+ var dfd = q.defer();
570
+
571
+ if(options && options.ext_user_id &&
572
+ options.ext_role && (options.productcode || options.ext_product_id))
573
+ {
574
+ // Passed all validations, Contruct API url
575
+ var url = self.config.DEFAULT_HOSTS.AUTH +
576
+ self.config.AUTH_API_URLS.entitleUserToProduct;
577
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
578
+
579
+ // Setup request with URL and Params
580
+ var requestAPI = request.post(url)
581
+ .set('Content-Type', 'application/json')
582
+ .set('Accept', 'application/json')
583
+ .send(options);
584
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
585
+
586
+ requestAPI.end(function(error, response) {
587
+ if(error) {
588
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
589
+ dfd.reject(error);
590
+ }
591
+ else { dfd.resolve(response.body); }
592
+ });
593
+ } else {
594
+ var err = {};
595
+ err.description = 'Missing mandatory keys in request options. \'ext_user_id\', \'ext_role\' and ' +
596
+ 'either of \'ext_product_id\' or \'productcode\' must be present.'
597
+ err.message = err.description;
598
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
599
+ dfd.reject(err);
600
+ }
601
+
602
+ return dfd.promise;
603
+ }
604
+
605
+ /*options = {
606
+ ext_user_id: 'string',
607
+ ext_actor_id: 'string',
608
+ productcode: 'string',
609
+ audit: 'boolean'
610
+ }*/
611
+ function unentitleUserToProduct(options) {
612
+ var self = this;
613
+ var dfd = q.defer();
614
+
615
+ if (options && options.ext_user_id && options.productcode && options.ext_actor_id) {
616
+ // Passed all validations, Contruct API url
617
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.entitleUserToProduct;
618
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
619
+
620
+ // Setup request with URL and Params
621
+ var requestAPI = request.delete(url)
622
+ .set('Content-Type', 'application/json')
623
+ .set('Accept', 'application/json')
624
+ .send(options);
625
+
626
+ if (self.traceid) {
627
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
628
+ }
629
+
630
+ requestAPI.end(function(error, response) {
631
+ if (error) {
632
+ var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
633
+ dfd.reject(err);
634
+ }
635
+ else {
636
+ dfd.resolve(response.body);
637
+ }
638
+ });
639
+ } else {
640
+ var err = {};
641
+ err.message = err.description = 'Missing mandatory keys in request options.' +
642
+ ' \'ext_user_id\', \'ext_actor_id\', and \'productcode\' must be present.';
643
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
644
+
645
+ dfd.reject(err);
646
+ }
647
+
648
+ return dfd.promise;
649
+ }
650
+
651
+ /* This function calls the ComproDLS API to micro entitle user to a product.
652
+ options = {
653
+ "ext_user_id": "string", // Mandatory
654
+ "feature_key": "string", // Mandatory
655
+ "feature_id": "string", // Mandatory
656
+ "context": "string", // Mandatory
657
+ "data": {}, // Optional
658
+ "productcode": "string", // one of productcode and ext_product_id is mandatory
659
+ "ext_product_id": "string",
660
+ "ext_entitlement_meta": { //Optional
661
+ "startdate": "epoch",
662
+ "enddate": "epoch" //mandatory, if ext_entitlement_meta provided.
663
+ }
664
+ }*/
665
+ function microEntitleUserToProduct(options) {
666
+ var self = this;
667
+ // Initializing promise
668
+ var dfd = q.defer();
669
+ var bValidOptions = true;
670
+ var err = {
671
+ description: '',
672
+ message: ''
673
+ };
674
+
675
+ if (!(options && options.ext_user_id && options.context && options.feature_key &&
676
+ options.feature_id)) {
677
+ bValidOptions = false;
678
+ err.description = 'ext_user_id or context or feature_key or feature_id ' +
679
+ 'not found in request options. ';
680
+ }
681
+
682
+ if (bValidOptions && (options.productcode || options.ext_product_id)) {
683
+ // Passed all validations, Contruct API url
684
+ var url = self.config.DEFAULT_HOSTS.AUTH +
685
+ self.config.AUTH_API_URLS.microEntitleUserToProduct;
686
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
687
+
688
+ // Setup request with URL and Params
689
+ var requestAPI = request.post(url)
690
+ .set('Content-Type', 'application/json')
691
+ .set('Accept', 'application/json')
692
+ .send(options);
693
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
694
+
695
+ requestAPI.end(function(error, response) {
696
+ if(error) {
697
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
698
+ dfd.reject(error);
699
+ }
700
+ else { dfd.resolve(response.body); }
701
+ });
702
+ } else {
703
+ if(!(options.productcode || options.ext_product_id)) {
704
+ err.description += 'Either of ext_product_id or productcode must be ' +
705
+ 'present in request options.';
706
+ }
707
+ err.message = err.description;
708
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
709
+ dfd.reject(err);
710
+ }
711
+
712
+ return dfd.promise;
713
+ }
714
+
715
+ /* This function calls the ComproDLS API to revoke micro entitlement of a user.
716
+ options = {
717
+ "ext_user_id": "string", // Mandatory
718
+ "feature_key": "string", // Mandatory
719
+ "context": "string", // Mandatory
720
+ "productcode": "string", // one of productcode and ext_product_id is mandatory
721
+ "ext_product_id": "string",
722
+ }*/
723
+ function revokeMicroEntitlementOfAUser(options) {
724
+ var self = this;
725
+ // Initializing promise
726
+ var dfd = q.defer();
727
+ var err = {
728
+ description: '',
729
+ message: ''
730
+ };
731
+
732
+ if((options && options.ext_user_id && options.context && options.feature_key &&
733
+ (options.productcode || options.ext_product_id))) {
734
+ // Passed all validations, Contruct API url
735
+ var url = self.config.DEFAULT_HOSTS.AUTH +
736
+ self.config.AUTH_API_URLS.microEntitleUserToProduct;
737
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
738
+
739
+ // Setup request with URL and Params
740
+ var requestAPI = request.delete(url)
741
+ .set('Content-Type', 'application/json')
742
+ .set('Accept', 'application/json')
743
+ .send(options);
744
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
745
+
746
+ requestAPI.end(function(error, response) {
747
+ if(error) {
748
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
749
+ dfd.reject(error);
750
+ }
751
+ else { dfd.resolve(response.body); }
752
+ });
753
+ }
754
+ else {
755
+ err.description = 'ext_user_id or context or feature_key not found or is empty in request options. ' +
756
+ 'Either productcode or ext_product_id must be provided.';
757
+ err.message = err.description;
758
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
759
+ dfd.reject(err);
760
+ }
761
+
762
+ return dfd.promise;
763
+ }
764
+
765
+ /*options = {
766
+ ext_product_id: 'string'
767
+ }*/
768
+ function getExtProduct(options) {
769
+ var self = this;
770
+ // Initializing promise
771
+ var dfd = q.defer();
772
+
773
+ if(options && options.ext_product_id)
774
+ {
775
+ // Passed all validations, Contruct API url
776
+ var url = self.config.DEFAULT_HOSTS.AUTH +
777
+ self.config.AUTH_API_URLS.getExtProductAPI;
778
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, extProductId: options.ext_product_id});
779
+
780
+ // Setup request with URL and Params
781
+ var requestAPI = request.get(url);
782
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
783
+
784
+ requestAPI.end(function(error, response) {
785
+ if(error) {
786
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
787
+ dfd.reject(error);
788
+ }
789
+ else { dfd.resolve(response.body); }
790
+ });
791
+ } else {
792
+ var err = {};
793
+ err.message = err.description = 'ext_product_id not found in request options.';
794
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
795
+ dfd.reject(err);
796
+ }
797
+
798
+ return dfd.promise;
799
+ }
800
+
801
+ /*options = {
802
+ spacekey: 'string'
803
+ }*/
804
+ function getSpaceDetails(options) {
805
+ var self = this;
806
+ // Initializing promise
807
+ var dfd = q.defer();
808
+
809
+ if(options && options.spacekey) {
810
+ // Passed all validations, Contruct API url
811
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getSpaceDetails;
812
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, spacekey: options.spacekey});
813
+
814
+ var params = { orgid: self.orgId };
815
+
816
+ // Setup request with URL and Params
817
+ var requestAPI = request.get(url).query(params);
818
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
819
+
820
+ // Setup token in Authorization header
821
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
822
+
823
+ requestAPI.end(function(error, response) {
824
+ if(error) {
825
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
826
+ dfd.reject(error);
827
+ }
828
+ else { dfd.resolve(response.body); }
829
+ });
830
+ } else {
831
+ var err = {};
832
+ err.message = err.description = 'spacekey not found in request options.';
833
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
834
+ dfd.reject(err);
835
+ }
836
+
837
+ return dfd.promise;
838
+ }
839
+
840
+ /*options = {
841
+ ext_user_id: 'string',
842
+ ext_role: 'string',
843
+ ext_first_name: 'string',
844
+ ext_last_name: 'string',
845
+ ext_email: 'string',
846
+ ref_id: 'string', (optional)
847
+ class_code: 'string'
848
+ }*/
849
+ function enrollUserInClass(options) {
850
+ var self = this;
851
+ // Initializing promise
852
+ var dfd = q.defer();
853
+
854
+ if(options && options.ext_user_id &&
855
+ options.ext_role && options.class_code)
856
+ {
857
+ // Passed all validations, Contruct API url
858
+ var url = self.config.DEFAULT_HOSTS.AUTH +
859
+ self.config.AUTH_API_URLS.enrollUserInClass;
860
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
861
+
862
+ // Setup request with URL and Params
863
+ var requestAPI = request.post(url)
864
+ .set('Content-Type', 'application/json')
865
+ .set('Accept', 'application/json')
866
+ .send(options);
867
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
868
+
869
+ requestAPI.end(function(error, response) {
870
+ if(error) {
871
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
872
+ dfd.reject(error);
873
+ }
874
+ else { dfd.resolve(response.body); }
875
+ });
876
+ } else {
877
+ var err = {};
878
+ err.message = err.description = 'ext_user_id or ext_role or class_code not found in request options.';
879
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
880
+ dfd.reject(err);
881
+ }
882
+
883
+ return dfd.promise;
884
+ }
885
+
886
+ /**
887
+ * This function calls the ComproDLS API to update user information.
888
+ * options = {
889
+ * "ext_user_id": "string",
890
+ * "ref_id": "string", // optional
891
+ * "ext_email": "string", // optional
892
+ * "ext_first_name": "string", // optional
893
+ * "ext_last_name": "string" // optional
894
+ * };
895
+ */
896
+ function updateUserInformation(options) {
897
+ var self = this;
898
+ // Initializing promise
899
+ var dfd = q.defer(), err = {};
900
+
901
+ if(options && options.ext_user_id)
902
+ {
903
+ // Passed all validations, Contruct API url
904
+ var url = self.config.DEFAULT_HOSTS.AUTH +
905
+ self.config.AUTH_API_URLS.updateUserInformation;
906
+ url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
907
+ var bodyParams = {
908
+ ext_user_id: options.ext_user_id
909
+ };
910
+ if(options.ref_id) { bodyParams.ref_id = options.ref_id; }
911
+ if(options.ext_email) { bodyParams.ext_email = options.ext_email; }
912
+ if(options.ext_first_name) { bodyParams.ext_first_name = options.ext_first_name; }
913
+ if(options.ext_last_name) { bodyParams.ext_last_name = options.ext_last_name; }
914
+ if(options.address) { bodyParams.address = options.address; }
915
+ // Setup request with URL and Params
916
+ var requestAPI = request.put(url)
917
+ .set('Content-Type', 'application/json')
918
+ .set('Accept', 'application/json')
919
+ .send(bodyParams);
920
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
921
+
922
+ requestAPI.end(function(error, response) {
923
+ if(error) {
924
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
925
+ dfd.reject(error);
926
+ }
927
+ else { dfd.resolve(response.body); }
928
+ });
929
+ } else {
930
+ err.message = err.description = 'Mandatory parameters not found in request options:' +
931
+ ' ["ext_user_id"]';
932
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
933
+ dfd.reject(err);
934
+ }
935
+
936
+ return dfd.promise;
937
+ }
938
+
939
+ /* options = {
940
+ "email": "string", // required
941
+ "status " : "string", // optional
942
+ };
943
+ */
944
+ function getInvitationsByEmail(options) {
945
+ var self = this;
946
+ // Initializing promise
947
+ var dfd = q.defer();
948
+ var err = {};
949
+ if (options && options.email) {
950
+
951
+ // Passed all validations, Contruct API url
952
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getInvitationsByEmail;
953
+ url = helpers.api.constructAPIUrl(url, { accountid: self.accountId });
954
+
955
+ var queryParam = { email: options.email };
956
+ if (options.status) { queryParam.status = options.status; }
957
+
958
+ // Setup request with URL and Params
959
+ var requestAPI = request.get(url).query(queryParam);
960
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
961
+
962
+ requestAPI.end(function (error, response) {
963
+ if (error) {
964
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
965
+ dfd.reject(err);
966
+ }
967
+ else { dfd.resolve(response.body); }
968
+ });
969
+ }
970
+ else {
971
+ err.message = err.description = 'email not found in request options.';
972
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
973
+ dfd.reject(err);
974
+ }
975
+ return dfd.promise;
976
+ }