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.
- package/.eslintrc +28 -28
- package/.github/workflows/npm-publish.yml +76 -0
- package/README.md +235 -235
- package/dist/comprodls-sdk.js +13543 -13543
- package/docs/npm-oidc-publishing-runbook.md +229 -0
- package/lib/comprodls.js +132 -132
- package/lib/config/index.js +356 -356
- package/lib/helpers/index.js +31 -31
- package/lib/helpers/lib/api/converter.js +129 -129
- package/lib/helpers/lib/api/index.js +46 -46
- package/lib/helpers/lib/errors.js +122 -122
- package/lib/helpers/lib/requestLayer.js +154 -154
- package/lib/helpers/lib/validator.js +192 -192
- package/lib/open_access/index.js +116 -116
- package/lib/services/analytics/index.js +1365 -1365
- package/lib/services/attempts/index.js +389 -389
- package/lib/services/auth/index.js +3708 -3708
- package/lib/services/authextn/index.js +1032 -1032
- package/lib/services/datasyncmanager/index.js +275 -275
- package/lib/services/drive/index.js +270 -270
- package/lib/services/integrations/index.js +525 -525
- package/lib/services/invitations/index.js +282 -282
- package/lib/services/product/index.js +343 -343
- package/lib/services/pub/index.js +530 -530
- package/lib/services/pushX/index.js +251 -251
- package/lib/services/pushX/pubnubClientWrapper.js +438 -438
- package/lib/services/rules/index.js +416 -416
- package/lib/services/spaces/index.js +999 -999
- package/lib/services/spacesextn/index.js +131 -131
- package/lib/services/superuser/index.js +160 -160
- package/lib/services/taxonomy/index.js +405 -405
- package/lib/services/workflows/index.js +406 -406
- package/lib/services/xapi/index.js +114 -114
- package/lib/token/index.js +120 -120
- package/lib/token/validations.js +85 -85
- package/package.json +5 -1
|
@@ -1,999 +1,999 @@
|
|
|
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
|
-
var Agent = require('agentkeepalive');
|
|
29
|
-
|
|
30
|
-
var helpers = require('../../helpers');
|
|
31
|
-
|
|
32
|
-
var DLSError = helpers.errors.DLSError;
|
|
33
|
-
|
|
34
|
-
module.exports = spaces;
|
|
35
|
-
|
|
36
|
-
var keepaliveAgent = new Agent({
|
|
37
|
-
timeout: 60000,
|
|
38
|
-
freeSocketTimeout: 30000
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
//Auth Adaptor Contsructor
|
|
42
|
-
function spaces(accountId) {
|
|
43
|
-
this.accountId = accountId;
|
|
44
|
-
return {
|
|
45
|
-
getUserSpaces: getUserSpaces.bind(this),
|
|
46
|
-
validateSpaceCode: validateSpaceCode.bind(this),
|
|
47
|
-
validateClassCode: validateClassCode.bind(this),
|
|
48
|
-
generateSpaceCode: generateSpaceCode.bind(this),
|
|
49
|
-
changeSpaceCode: changeSpaceCode.bind(this),
|
|
50
|
-
joinInstituteSpace: joinInstituteSpace.bind(this),
|
|
51
|
-
provisionSpacesToStudent: provisionSpacesToStudent.bind(this),
|
|
52
|
-
provisionSpacesToTeacher: provisionSpacesToTeacher.bind(this),
|
|
53
|
-
provisionBulkSpaces: provisionBulkSpaces.bind(this),
|
|
54
|
-
shadowProvision: shadowProvision.bind(this),
|
|
55
|
-
entitleUserToProduct: entitleUserToProduct.bind(this),
|
|
56
|
-
unentitleUserToProduct: unentitleUserToProduct.bind(this),
|
|
57
|
-
revokeMicroEntitlementOfAUser: revokeMicroEntitlementOfAUser.bind(this),
|
|
58
|
-
microEntitleUserToProduct: microEntitleUserToProduct.bind(this),
|
|
59
|
-
bulkMicroEntitleProductToUser: bulkMicroEntitleProductToUser.bind(this),
|
|
60
|
-
enrollUserInClass: enrollUserInClass.bind(this),
|
|
61
|
-
getExtProduct: getExtProduct.bind(this),
|
|
62
|
-
getSpaceDetails: getSpaceDetails.bind(this),
|
|
63
|
-
updateUserInformation: updateUserInformation.bind(this),
|
|
64
|
-
updateUserSpace: updateUserSpace.bind(this),
|
|
65
|
-
getInvitationsByEmail: getInvitationsByEmail.bind(this),
|
|
66
|
-
updateInstituteTitle: updateInstituteTitle.bind(this)
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Wiki Link for SDK params
|
|
72
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getuserspacesparams
|
|
73
|
-
*/
|
|
74
|
-
function getUserSpaces(options) {
|
|
75
|
-
var self = this;
|
|
76
|
-
// Initializing promise
|
|
77
|
-
var dfd = q.defer();
|
|
78
|
-
// Validations
|
|
79
|
-
|
|
80
|
-
if(options && options.extuserid) {
|
|
81
|
-
// Passed all validations, Contruct API url
|
|
82
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
83
|
-
self.config.AUTH_API_URLS.getUserSpaces;
|
|
84
|
-
url = helpers.api.constructAPIUrl(url, {
|
|
85
|
-
accountid: self.accountId, extuserid: options.extuserid
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
var params = {};
|
|
89
|
-
if(options.spaceRole) { params.spaceRole = options.spaceRole; }
|
|
90
|
-
if(options.spaceType) { params.spaceType = options.spaceType; }
|
|
91
|
-
if(options.spaceOrgContext) { params.spaceOrgContext = options.spaceOrgContext; }
|
|
92
|
-
if(options.details) { params.details = options.details; }
|
|
93
|
-
if(options.cursor) { params.cursor = options.cursor; }
|
|
94
|
-
|
|
95
|
-
// Setup request with URL and Params
|
|
96
|
-
var requestAPI = request.get(url).query(params);
|
|
97
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
98
|
-
|
|
99
|
-
requestAPI.end(function(error, response) {
|
|
100
|
-
if(error) {
|
|
101
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
102
|
-
dfd.reject(err);
|
|
103
|
-
}
|
|
104
|
-
else { dfd.resolve(response.body); }
|
|
105
|
-
});
|
|
106
|
-
} else {
|
|
107
|
-
var err = {};
|
|
108
|
-
err.message = err.description = 'extuserid not found in request options.';
|
|
109
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
110
|
-
dfd.reject(err);
|
|
111
|
-
}
|
|
112
|
-
return dfd.promise;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Wiki Link for SDK params
|
|
117
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#validatespacecodeparams
|
|
118
|
-
*/
|
|
119
|
-
function validateSpaceCode(options) {
|
|
120
|
-
var self = this;
|
|
121
|
-
// Initializing promise
|
|
122
|
-
var dfd = q.defer();
|
|
123
|
-
|
|
124
|
-
if(options && options.spaceCodeBody && options.spaceCodeBody.space_code) {
|
|
125
|
-
// Passed all validations, Contruct API url
|
|
126
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
127
|
-
self.config.AUTH_API_URLS.validateSpaceCode;
|
|
128
|
-
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
|
|
129
|
-
|
|
130
|
-
// Setup request with URL and Params
|
|
131
|
-
var requestAPI = request.post(url)
|
|
132
|
-
.set('Content-Type', 'application/json')
|
|
133
|
-
.set('Accept', 'application/json')
|
|
134
|
-
.send(options.spaceCodeBody);
|
|
135
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
136
|
-
|
|
137
|
-
requestAPI.end(function(error, response) {
|
|
138
|
-
if(error) {
|
|
139
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
140
|
-
dfd.reject(err);
|
|
141
|
-
}
|
|
142
|
-
else { dfd.resolve(response.body); }
|
|
143
|
-
});
|
|
144
|
-
} else {
|
|
145
|
-
var err = {};
|
|
146
|
-
err.message = err.description = 'spaceCodeBody or space_code not found in request options.';
|
|
147
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
148
|
-
dfd.reject(err);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return dfd.promise;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Wiki Link for SDK params
|
|
156
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#validateclasscodeparams
|
|
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(err);
|
|
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
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Wiki Link for SDK params
|
|
201
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#generatespacecodeparams
|
|
202
|
-
*/
|
|
203
|
-
function generateSpaceCode(options) {
|
|
204
|
-
var self = this;
|
|
205
|
-
|
|
206
|
-
// Initializing promise
|
|
207
|
-
var dfd = q.defer();
|
|
208
|
-
|
|
209
|
-
// Passed all validations, Contruct API url
|
|
210
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
211
|
-
self.config.AUTH_API_URLS.generateSpaceCode;
|
|
212
|
-
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
|
|
213
|
-
|
|
214
|
-
var bodyParams = {};
|
|
215
|
-
if(options.ignore_words) { bodyParams.ignore_words = options.ignore_words; }
|
|
216
|
-
// Setup request with URL and Params
|
|
217
|
-
var requestAPI = request.post(url)
|
|
218
|
-
.set('Content-Type', 'application/json')
|
|
219
|
-
.set('Accept', 'application/json')
|
|
220
|
-
.send(bodyParams);
|
|
221
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
222
|
-
|
|
223
|
-
requestAPI.end(function(error, response) {
|
|
224
|
-
if(error) {
|
|
225
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
226
|
-
dfd.reject(err);
|
|
227
|
-
}
|
|
228
|
-
else { dfd.resolve(response); }
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
return dfd.promise;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Wiki Link for SDK params
|
|
236
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#changespacecodeparams
|
|
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(err);
|
|
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
|
-
* Wiki Link for SDK params
|
|
276
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#joininstitutespaceparams
|
|
277
|
-
*/
|
|
278
|
-
function joinInstituteSpace(options) {
|
|
279
|
-
var self = this;
|
|
280
|
-
// Initializing promise
|
|
281
|
-
var dfd = q.defer();
|
|
282
|
-
|
|
283
|
-
if(options && options.ext_user_id &&
|
|
284
|
-
options.ext_role && options.space_code)
|
|
285
|
-
{
|
|
286
|
-
// Passed all validations, Contruct API url
|
|
287
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
288
|
-
self.config.AUTH_API_URLS.joinInstituteSpace;
|
|
289
|
-
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
|
|
290
|
-
|
|
291
|
-
// Setup request with URL and Params
|
|
292
|
-
var requestAPI = request.post(url)
|
|
293
|
-
.set('Content-Type', 'application/json')
|
|
294
|
-
.set('Accept', 'application/json')
|
|
295
|
-
.send(options);
|
|
296
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
297
|
-
|
|
298
|
-
requestAPI.end(function(error, response) {
|
|
299
|
-
if(error) {
|
|
300
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
301
|
-
dfd.reject(err);
|
|
302
|
-
}
|
|
303
|
-
else { dfd.resolve(response.body); }
|
|
304
|
-
});
|
|
305
|
-
} else {
|
|
306
|
-
var err = {};
|
|
307
|
-
err.message = err.description = 'ext_user_id or ext_role or space_code not found in request options.';
|
|
308
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
309
|
-
dfd.reject(err);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return dfd.promise;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Wiki Link for SDK params
|
|
317
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#provisionspacestostudentparams
|
|
318
|
-
*/
|
|
319
|
-
function provisionSpacesToStudent(options) {
|
|
320
|
-
var self = this;
|
|
321
|
-
// Initializing promise
|
|
322
|
-
var dfd = q.defer();
|
|
323
|
-
var err = {};
|
|
324
|
-
if(options && options.ext_user_id && options.ext_role) {
|
|
325
|
-
|
|
326
|
-
// Passed all validations, Contruct API url
|
|
327
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
328
|
-
self.config.AUTH_API_URLS.provisionSpacesToStudent;
|
|
329
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
330
|
-
|
|
331
|
-
// Setup request with URL and Params
|
|
332
|
-
var requestAPI = request.post(url)
|
|
333
|
-
.set('Content-Type', 'application/json')
|
|
334
|
-
.set('Accept', 'application/json')
|
|
335
|
-
.send(options);
|
|
336
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
337
|
-
|
|
338
|
-
requestAPI.end(function(error, response) {
|
|
339
|
-
if(error) {
|
|
340
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
341
|
-
dfd.reject(err);
|
|
342
|
-
}
|
|
343
|
-
else { dfd.resolve(response.body); }
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
err.message = err.description = 'ext_user_id or ext_role not found in request options.';
|
|
348
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
349
|
-
dfd.reject(err);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return dfd.promise;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Wiki Link for SDK params
|
|
357
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#provisionspacestoteacherparams
|
|
358
|
-
*/
|
|
359
|
-
function provisionSpacesToTeacher(options) {
|
|
360
|
-
var self = this;
|
|
361
|
-
// Initializing promise
|
|
362
|
-
var dfd = q.defer();
|
|
363
|
-
|
|
364
|
-
if(options && options.ext_user_id && options.ext_role)
|
|
365
|
-
{
|
|
366
|
-
// Passed all validations, Contruct API url
|
|
367
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
368
|
-
self.config.AUTH_API_URLS.provisionSpacesToTeacher;
|
|
369
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
370
|
-
|
|
371
|
-
// Setup request with URL and Params
|
|
372
|
-
var requestAPI = request.post(url)
|
|
373
|
-
.set('Content-Type', 'application/json')
|
|
374
|
-
.set('Accept', 'application/json')
|
|
375
|
-
.send(options);
|
|
376
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
377
|
-
|
|
378
|
-
requestAPI.end(function(error, response) {
|
|
379
|
-
if(error) {
|
|
380
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
381
|
-
dfd.reject(err);
|
|
382
|
-
}
|
|
383
|
-
else { dfd.resolve(response.body); }
|
|
384
|
-
});
|
|
385
|
-
} else {
|
|
386
|
-
var err = {};
|
|
387
|
-
err.message = err.description = 'Mandatory parameters [rxt_user_id, ext_role] not found in request options.';
|
|
388
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
389
|
-
dfd.reject(err);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return dfd.promise;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Wiki Link for SDK params
|
|
397
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#provisionbulkspacesparams
|
|
398
|
-
*/
|
|
399
|
-
function provisionBulkSpaces(options) {
|
|
400
|
-
var self = this;
|
|
401
|
-
// Initializing promise
|
|
402
|
-
var dfd = q.defer();
|
|
403
|
-
// Validations
|
|
404
|
-
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
405
|
-
if(err) { dfd.reject(err); }
|
|
406
|
-
else {
|
|
407
|
-
if(options && options.users && options.space_title) {
|
|
408
|
-
// Passed all validations, Contruct API url
|
|
409
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
410
|
-
self.config.AUTH_API_URLS.provisionBulkSpaces;
|
|
411
|
-
url = helpers.api.constructAPIUrl(url, { orgId : self.orgId });
|
|
412
|
-
|
|
413
|
-
// Setup request with URL and Params
|
|
414
|
-
var requestAPI = request.post(url)
|
|
415
|
-
.set('Content-Type', 'application/json')
|
|
416
|
-
.set('Accept', 'application/json')
|
|
417
|
-
.send(options);
|
|
418
|
-
|
|
419
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
420
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
421
|
-
|
|
422
|
-
requestAPI.end(function(error, response) {
|
|
423
|
-
if(error) {
|
|
424
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
425
|
-
dfd.reject(err);
|
|
426
|
-
}
|
|
427
|
-
else { dfd.resolve(response.body); }
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
err = {};
|
|
432
|
-
err.message = err.description = 'Mandatory parameters: space_title or users not found in request options.';
|
|
433
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
434
|
-
dfd.reject(err);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return dfd.promise;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Wiki Link for SDK params
|
|
443
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#shadowprovisionparams
|
|
444
|
-
*/
|
|
445
|
-
function shadowProvision(options) {
|
|
446
|
-
var self = this;
|
|
447
|
-
//Initializing promise
|
|
448
|
-
var dfd = q.defer(), err = {};
|
|
449
|
-
//Validations
|
|
450
|
-
if (options && options.ext_user_id && options.ext_role) {
|
|
451
|
-
//Passed all validations, Contruct API url
|
|
452
|
-
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.shadowProvision;
|
|
453
|
-
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
454
|
-
|
|
455
|
-
// Setup request with URL and Params
|
|
456
|
-
var requestAPI = request.post(url)
|
|
457
|
-
.set('Content-Type', 'application/json')
|
|
458
|
-
.set('Accept', 'application/json')
|
|
459
|
-
.send(options);
|
|
460
|
-
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
461
|
-
|
|
462
|
-
requestAPI
|
|
463
|
-
.agent(keepaliveAgent)
|
|
464
|
-
.end(function (err, response) {
|
|
465
|
-
if (err) {
|
|
466
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
467
|
-
dfd.reject(err);
|
|
468
|
-
}
|
|
469
|
-
else { dfd.resolve(response.body); }
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
err.message = err.description = 'Mandatory parameters: ext_user_id or ext_role not ' +
|
|
474
|
-
'found in request options.';
|
|
475
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
476
|
-
dfd.reject(err);
|
|
477
|
-
}
|
|
478
|
-
return dfd.promise;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Wiki Link for SDK params
|
|
483
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#entitleusertoproductparams
|
|
484
|
-
*/
|
|
485
|
-
function entitleUserToProduct(options) {
|
|
486
|
-
var self = this;
|
|
487
|
-
// Initializing promise
|
|
488
|
-
var dfd = q.defer();
|
|
489
|
-
|
|
490
|
-
if(options && options.ext_user_id &&
|
|
491
|
-
options.ext_role && (options.productcode || options.ext_product_id))
|
|
492
|
-
{
|
|
493
|
-
// Passed all validations, Contruct API url
|
|
494
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
495
|
-
self.config.AUTH_API_URLS.entitleUserToProduct;
|
|
496
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
497
|
-
|
|
498
|
-
// Setup request with URL and Params
|
|
499
|
-
var requestAPI = request.post(url)
|
|
500
|
-
.set('Content-Type', 'application/json')
|
|
501
|
-
.set('Accept', 'application/json')
|
|
502
|
-
.send(options);
|
|
503
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
504
|
-
|
|
505
|
-
requestAPI.end(function(error, response) {
|
|
506
|
-
if(error) {
|
|
507
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
508
|
-
dfd.reject(err);
|
|
509
|
-
}
|
|
510
|
-
else { dfd.resolve(response.body); }
|
|
511
|
-
});
|
|
512
|
-
} else {
|
|
513
|
-
var err = {};
|
|
514
|
-
err.description = 'Missing mandatory keys in request options. \'ext_user_id\', \'ext_role\' and ' +
|
|
515
|
-
'either of \'ext_product_id\' or \'productcode\' must be present.';
|
|
516
|
-
err.message = err.description;
|
|
517
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
518
|
-
dfd.reject(err);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
return dfd.promise;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Wiki Link for SDK params
|
|
526
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#unentitleusertoproductparams
|
|
527
|
-
*/
|
|
528
|
-
function unentitleUserToProduct(options) {
|
|
529
|
-
var self = this;
|
|
530
|
-
var dfd = q.defer();
|
|
531
|
-
|
|
532
|
-
if (options && options.ext_user_id && options.productcode && options.ext_actor_id
|
|
533
|
-
&& (options.audit !== undefined)) {
|
|
534
|
-
// Passed all validations, Contruct API url
|
|
535
|
-
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.entitleUserToProduct;
|
|
536
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
537
|
-
|
|
538
|
-
// Setup request with URL and Params
|
|
539
|
-
var requestAPI = request.delete(url)
|
|
540
|
-
.set('Content-Type', 'application/json')
|
|
541
|
-
.set('Accept', 'application/json')
|
|
542
|
-
.send(options);
|
|
543
|
-
|
|
544
|
-
if (self.traceid) {
|
|
545
|
-
requestAPI.set('X-Amzn-Trace-Id', self.traceid);
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
requestAPI.end(function(error, response) {
|
|
549
|
-
if (error) {
|
|
550
|
-
var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
551
|
-
dfd.reject(err);
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
dfd.resolve(response.body);
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
} else {
|
|
558
|
-
var err = {};
|
|
559
|
-
err.message = err.description = 'Missing mandatory keys in request options.' +
|
|
560
|
-
' \'ext_user_id\', \'ext_actor_id\', \'productcode\' and \'audit\'' +
|
|
561
|
-
' must be present';
|
|
562
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
563
|
-
|
|
564
|
-
dfd.reject(err);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
return dfd.promise;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Wiki Link for SDK params
|
|
572
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#microentitleusertoproductparams
|
|
573
|
-
*/
|
|
574
|
-
function microEntitleUserToProduct(options) {
|
|
575
|
-
var self = this;
|
|
576
|
-
// Initializing promise
|
|
577
|
-
var dfd = q.defer();
|
|
578
|
-
var bValidOptions = true;
|
|
579
|
-
var err = {
|
|
580
|
-
description: '',
|
|
581
|
-
message: ''
|
|
582
|
-
};
|
|
583
|
-
|
|
584
|
-
if (!(options && options.ext_user_id && options.context && options.feature_key &&
|
|
585
|
-
options.feature_id)) {
|
|
586
|
-
bValidOptions = false;
|
|
587
|
-
err.description = 'ext_user_id or context or feature_key or feature_id ' +
|
|
588
|
-
'not found in request options. ';
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
if (bValidOptions && (options.productcode || options.ext_product_id)) {
|
|
592
|
-
// Passed all validations, Contruct API url
|
|
593
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
594
|
-
self.config.AUTH_API_URLS.microEntitleUserToProduct;
|
|
595
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
596
|
-
|
|
597
|
-
// Setup request with URL and Params
|
|
598
|
-
var requestAPI = request.post(url)
|
|
599
|
-
.set('Content-Type', 'application/json')
|
|
600
|
-
.set('Accept', 'application/json')
|
|
601
|
-
.send(options);
|
|
602
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
603
|
-
|
|
604
|
-
requestAPI.end(function(error, response) {
|
|
605
|
-
if(error) {
|
|
606
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
607
|
-
dfd.reject(err);
|
|
608
|
-
}
|
|
609
|
-
else { dfd.resolve(response.body); }
|
|
610
|
-
});
|
|
611
|
-
} else {
|
|
612
|
-
if(!(options.productcode || options.ext_product_id)) {
|
|
613
|
-
err.description += 'Either of ext_product_id or productcode must be ' +
|
|
614
|
-
'present in request options.';
|
|
615
|
-
}
|
|
616
|
-
err.message = err.description;
|
|
617
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
618
|
-
dfd.reject(err);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
return dfd.promise;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Wiki Link for SDK params
|
|
626
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#bulkmicroentitleproducttouserparams
|
|
627
|
-
*/
|
|
628
|
-
function bulkMicroEntitleProductToUser(options) {
|
|
629
|
-
var self = this;
|
|
630
|
-
// Initializing promise
|
|
631
|
-
var dfd = q.defer();
|
|
632
|
-
|
|
633
|
-
if(options && options['micro-entitlements'])
|
|
634
|
-
{
|
|
635
|
-
// Passed all validations, Contruct API url
|
|
636
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
637
|
-
self.config.AUTH_API_URLS.bulkMicroEntitleProductToUser;
|
|
638
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
639
|
-
|
|
640
|
-
// Setup request with URL and Params
|
|
641
|
-
var requestAPI = request.post(url)
|
|
642
|
-
.set('Content-Type', 'application/json')
|
|
643
|
-
.set('Accept', 'application/json')
|
|
644
|
-
.send(options);
|
|
645
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
646
|
-
|
|
647
|
-
requestAPI.end(function(error, response) {
|
|
648
|
-
if(error) {
|
|
649
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
650
|
-
dfd.reject(err);
|
|
651
|
-
}
|
|
652
|
-
else { dfd.resolve(response.body); }
|
|
653
|
-
});
|
|
654
|
-
} else {
|
|
655
|
-
var err = {};
|
|
656
|
-
err.description = 'Missing mandatory keys in request options.' +
|
|
657
|
-
' \'micro-entitlements\' must be present.';
|
|
658
|
-
err.message = err.description;
|
|
659
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
660
|
-
dfd.reject(err);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
return dfd.promise;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* Wiki Link for SDK params
|
|
668
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#revokemicroentitlementofauserparams
|
|
669
|
-
*/
|
|
670
|
-
function revokeMicroEntitlementOfAUser(options) {
|
|
671
|
-
var self = this;
|
|
672
|
-
// Initializing promise
|
|
673
|
-
var dfd = q.defer();
|
|
674
|
-
var err = {
|
|
675
|
-
description: '',
|
|
676
|
-
message: ''
|
|
677
|
-
};
|
|
678
|
-
|
|
679
|
-
if((options && options.ext_user_id && options.context && options.feature_key &&
|
|
680
|
-
options.ext_actor_id && (options.audit !== undefined) &&
|
|
681
|
-
(options.productcode || options.ext_product_id))) {
|
|
682
|
-
// Passed all validations, Contruct API url
|
|
683
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
684
|
-
self.config.AUTH_API_URLS.microEntitleUserToProduct;
|
|
685
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
686
|
-
|
|
687
|
-
// Setup request with URL and Params
|
|
688
|
-
var requestAPI = request.delete(url)
|
|
689
|
-
.set('Content-Type', 'application/json')
|
|
690
|
-
.set('Accept', 'application/json')
|
|
691
|
-
.send(options);
|
|
692
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
693
|
-
|
|
694
|
-
requestAPI.end(function(error, response) {
|
|
695
|
-
if(error) {
|
|
696
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
697
|
-
dfd.reject(err);
|
|
698
|
-
}
|
|
699
|
-
else { dfd.resolve(response.body); }
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
else {
|
|
703
|
-
err.description = 'ext_user_id or context or feature_key or ext_actor_id or audit field ' +
|
|
704
|
-
'not found or is empty in request options. Either productcode or ' +
|
|
705
|
-
'ext_product_id must be provided.';
|
|
706
|
-
err.message = err.description;
|
|
707
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
708
|
-
dfd.reject(err);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
return dfd.promise;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* Wiki Link for SDK params
|
|
716
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getextproductparams
|
|
717
|
-
*/
|
|
718
|
-
function getExtProduct(options) {
|
|
719
|
-
var self = this;
|
|
720
|
-
// Initializing promise
|
|
721
|
-
var dfd = q.defer();
|
|
722
|
-
|
|
723
|
-
if(options && options.ext_product_id)
|
|
724
|
-
{
|
|
725
|
-
// Passed all validations, Contruct API url
|
|
726
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
727
|
-
self.config.AUTH_API_URLS.getExtProductAPI;
|
|
728
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, extProductId: options.ext_product_id});
|
|
729
|
-
|
|
730
|
-
// Setup request with URL and Params
|
|
731
|
-
var requestAPI = request.get(url);
|
|
732
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
733
|
-
|
|
734
|
-
requestAPI.end(function(error, response) {
|
|
735
|
-
if(error) {
|
|
736
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
737
|
-
dfd.reject(err);
|
|
738
|
-
}
|
|
739
|
-
else { dfd.resolve(response.body); }
|
|
740
|
-
});
|
|
741
|
-
} else {
|
|
742
|
-
var err = {};
|
|
743
|
-
err.message = err.description = 'ext_product_id not found in request options.';
|
|
744
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
745
|
-
dfd.reject(err);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
return dfd.promise;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* Wiki Link for SDK params
|
|
753
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getspacedetailsparams
|
|
754
|
-
*/
|
|
755
|
-
function getSpaceDetails(options) {
|
|
756
|
-
var self = this;
|
|
757
|
-
// Initializing promise
|
|
758
|
-
var dfd = q.defer();
|
|
759
|
-
|
|
760
|
-
if(options && options.spacekey) {
|
|
761
|
-
// Passed all validations, Contruct API url
|
|
762
|
-
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getSpaceDetails;
|
|
763
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, spacekey: options.spacekey});
|
|
764
|
-
|
|
765
|
-
var params = { orgid: self.orgId };
|
|
766
|
-
|
|
767
|
-
// Setup request with URL and Params
|
|
768
|
-
var requestAPI = request.get(url).query(params);
|
|
769
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
770
|
-
|
|
771
|
-
// Setup token in Authorization header
|
|
772
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
773
|
-
|
|
774
|
-
requestAPI.end(function(error, response) {
|
|
775
|
-
if(error) {
|
|
776
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
777
|
-
dfd.reject(err);
|
|
778
|
-
}
|
|
779
|
-
else { dfd.resolve(response.body); }
|
|
780
|
-
});
|
|
781
|
-
} else {
|
|
782
|
-
var err = {};
|
|
783
|
-
err.message = err.description = 'spacekey not found in request options.';
|
|
784
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
785
|
-
dfd.reject(err);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
return dfd.promise;
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* Wiki Link for SDK params
|
|
793
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#enrolluserinclassparams
|
|
794
|
-
*/
|
|
795
|
-
function enrollUserInClass(options) {
|
|
796
|
-
var self = this;
|
|
797
|
-
// Initializing promise
|
|
798
|
-
var dfd = q.defer();
|
|
799
|
-
|
|
800
|
-
if(options && options.ext_user_id &&
|
|
801
|
-
options.ext_role && options.class_code)
|
|
802
|
-
{
|
|
803
|
-
// Passed all validations, Contruct API url
|
|
804
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
805
|
-
self.config.AUTH_API_URLS.enrollUserInClass;
|
|
806
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
807
|
-
|
|
808
|
-
// Setup request with URL and Params
|
|
809
|
-
var requestAPI = request.post(url)
|
|
810
|
-
.set('Content-Type', 'application/json')
|
|
811
|
-
.set('Accept', 'application/json')
|
|
812
|
-
.send(options);
|
|
813
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
814
|
-
|
|
815
|
-
requestAPI.end(function(error, response) {
|
|
816
|
-
if(error) {
|
|
817
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
818
|
-
dfd.reject(err);
|
|
819
|
-
}
|
|
820
|
-
else { dfd.resolve(response.body); }
|
|
821
|
-
});
|
|
822
|
-
} else {
|
|
823
|
-
var err = {};
|
|
824
|
-
err.message = err.description = 'ext_user_id or ext_role or class_code not found in request options.';
|
|
825
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
826
|
-
dfd.reject(err);
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
return dfd.promise;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
/**
|
|
833
|
-
* Wiki Link for SDK params
|
|
834
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#updateuserinformationparams
|
|
835
|
-
*/
|
|
836
|
-
function updateUserInformation(options) {
|
|
837
|
-
var self = this;
|
|
838
|
-
// Initializing promise
|
|
839
|
-
var dfd = q.defer(), err = {};
|
|
840
|
-
|
|
841
|
-
if(options && options.ext_user_id)
|
|
842
|
-
{
|
|
843
|
-
// Passed all validations, Contruct API url
|
|
844
|
-
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
845
|
-
self.config.AUTH_API_URLS.updateUserInformation;
|
|
846
|
-
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
847
|
-
var bodyParams = {
|
|
848
|
-
ext_user_id: options.ext_user_id
|
|
849
|
-
};
|
|
850
|
-
if(options.ref_id) { bodyParams.ref_id = options.ref_id; }
|
|
851
|
-
if(options.ext_email) { bodyParams.ext_email = options.ext_email; }
|
|
852
|
-
if(options.ext_first_name) { bodyParams.ext_first_name = options.ext_first_name; }
|
|
853
|
-
if(options.ext_last_name) { bodyParams.ext_last_name = options.ext_last_name; }
|
|
854
|
-
if(options.address) { bodyParams.address = options.address; }
|
|
855
|
-
// Setup request with URL and Params
|
|
856
|
-
var requestAPI = request.put(url)
|
|
857
|
-
.set('Content-Type', 'application/json')
|
|
858
|
-
.set('Accept', 'application/json')
|
|
859
|
-
.send(bodyParams);
|
|
860
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
861
|
-
|
|
862
|
-
requestAPI.end(function(error, response) {
|
|
863
|
-
if(error) {
|
|
864
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
865
|
-
dfd.reject(err);
|
|
866
|
-
}
|
|
867
|
-
else { dfd.resolve(response.body); }
|
|
868
|
-
});
|
|
869
|
-
} else {
|
|
870
|
-
err.message = err.description = 'Mandatory parameters not found in request options:' +
|
|
871
|
-
' ["ext_user_id"]';
|
|
872
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
873
|
-
dfd.reject(err);
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
return dfd.promise;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
/**
|
|
880
|
-
* Wiki Link for SDK params
|
|
881
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#updateuserspaceparams
|
|
882
|
-
*/
|
|
883
|
-
function updateUserSpace(options) {
|
|
884
|
-
var self = this;
|
|
885
|
-
|
|
886
|
-
// Initializing promise
|
|
887
|
-
var deferred = q.defer();
|
|
888
|
-
var error;
|
|
889
|
-
|
|
890
|
-
// Validate request input.
|
|
891
|
-
if (options && options.extuserid && options.spacekey && options.body) {
|
|
892
|
-
// Passed all validations, Contruct API url
|
|
893
|
-
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.updateUserSpace;
|
|
894
|
-
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId, extuserid: options.extuserid, spacekey: options.spacekey });
|
|
895
|
-
|
|
896
|
-
// Setup request with URL and Params
|
|
897
|
-
var requestAPI = request.put(url)
|
|
898
|
-
.set('Content-Type', 'application/json')
|
|
899
|
-
.set('Accept', 'application/json')
|
|
900
|
-
.send(options.body);
|
|
901
|
-
|
|
902
|
-
// Add 'trace_id' to the request headers.
|
|
903
|
-
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
904
|
-
|
|
905
|
-
requestAPI
|
|
906
|
-
.agent(keepaliveAgent)
|
|
907
|
-
.end(function(err, response) {
|
|
908
|
-
if (err) {
|
|
909
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
910
|
-
deferred.reject(error);
|
|
911
|
-
} else {
|
|
912
|
-
deferred.resolve(response.body);
|
|
913
|
-
}
|
|
914
|
-
});
|
|
915
|
-
} else {
|
|
916
|
-
var err = {};
|
|
917
|
-
err.message = err.description = 'Missing mandatory params: \'extuserid\' or \'spacekey\' or \'body\' not found in the request options.';
|
|
918
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
919
|
-
deferred.reject(error);
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
return deferred.promise;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
/**
|
|
926
|
-
* Wiki Link for SDK params
|
|
927
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getinvitationsbyemailparams
|
|
928
|
-
*/
|
|
929
|
-
function getInvitationsByEmail(options) {
|
|
930
|
-
var self = this;
|
|
931
|
-
// Initializing promise
|
|
932
|
-
var dfd = q.defer();
|
|
933
|
-
var err = {};
|
|
934
|
-
if (options && options.email) {
|
|
935
|
-
|
|
936
|
-
// Passed all validations, Contruct API url
|
|
937
|
-
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getInvitationsByEmail;
|
|
938
|
-
url = helpers.api.constructAPIUrl(url, { accountid: self.accountId });
|
|
939
|
-
|
|
940
|
-
var queryParam = { email: options.email };
|
|
941
|
-
if (options.status) { queryParam.status = options.status; }
|
|
942
|
-
|
|
943
|
-
// Setup request with URL and Params
|
|
944
|
-
var requestAPI = request.get(url).query(queryParam);
|
|
945
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
946
|
-
|
|
947
|
-
requestAPI.end(function (error, response) {
|
|
948
|
-
if (error) {
|
|
949
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
950
|
-
dfd.reject(err);
|
|
951
|
-
}
|
|
952
|
-
else { dfd.resolve(response.body); }
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
else {
|
|
956
|
-
err.message = err.description = 'email not found in request options.';
|
|
957
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
958
|
-
dfd.reject(err);
|
|
959
|
-
}
|
|
960
|
-
return dfd.promise;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
/**
|
|
964
|
-
* Wiki Link for SDK params
|
|
965
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#updateinstitutetitleparams
|
|
966
|
-
*/
|
|
967
|
-
function updateInstituteTitle(options){
|
|
968
|
-
var self = this;
|
|
969
|
-
// Initializing promise
|
|
970
|
-
var dfd = q.defer();
|
|
971
|
-
var err = {};
|
|
972
|
-
if (options && options.space_code && options.body && options.body.ext_actor_id ) {
|
|
973
|
-
// Passed all validations, Contruct API url
|
|
974
|
-
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.updateInstituteTitle;
|
|
975
|
-
url = helpers.api.constructAPIUrl(url,
|
|
976
|
-
{ accountId: self.accountId, instituteSpaceCode: options.space_code });
|
|
977
|
-
|
|
978
|
-
// Setup request with URL and Params
|
|
979
|
-
var requestAPI = request.put(url)
|
|
980
|
-
.set('Content-Type', 'application/json')
|
|
981
|
-
.set('Accept', 'application/json')
|
|
982
|
-
.send(options.body);
|
|
983
|
-
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
984
|
-
|
|
985
|
-
requestAPI.end(function (error, response) {
|
|
986
|
-
if (error) {
|
|
987
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
988
|
-
dfd.reject(err);
|
|
989
|
-
}
|
|
990
|
-
else { dfd.resolve(response.body); }
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
else {
|
|
994
|
-
err.message = err.description = 'space_code or ext_actor_id not found in request options.';
|
|
995
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
996
|
-
dfd.reject(err);
|
|
997
|
-
}
|
|
998
|
-
return dfd.promise;
|
|
999
|
-
}
|
|
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
|
+
var Agent = require('agentkeepalive');
|
|
29
|
+
|
|
30
|
+
var helpers = require('../../helpers');
|
|
31
|
+
|
|
32
|
+
var DLSError = helpers.errors.DLSError;
|
|
33
|
+
|
|
34
|
+
module.exports = spaces;
|
|
35
|
+
|
|
36
|
+
var keepaliveAgent = new Agent({
|
|
37
|
+
timeout: 60000,
|
|
38
|
+
freeSocketTimeout: 30000
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
//Auth Adaptor Contsructor
|
|
42
|
+
function spaces(accountId) {
|
|
43
|
+
this.accountId = accountId;
|
|
44
|
+
return {
|
|
45
|
+
getUserSpaces: getUserSpaces.bind(this),
|
|
46
|
+
validateSpaceCode: validateSpaceCode.bind(this),
|
|
47
|
+
validateClassCode: validateClassCode.bind(this),
|
|
48
|
+
generateSpaceCode: generateSpaceCode.bind(this),
|
|
49
|
+
changeSpaceCode: changeSpaceCode.bind(this),
|
|
50
|
+
joinInstituteSpace: joinInstituteSpace.bind(this),
|
|
51
|
+
provisionSpacesToStudent: provisionSpacesToStudent.bind(this),
|
|
52
|
+
provisionSpacesToTeacher: provisionSpacesToTeacher.bind(this),
|
|
53
|
+
provisionBulkSpaces: provisionBulkSpaces.bind(this),
|
|
54
|
+
shadowProvision: shadowProvision.bind(this),
|
|
55
|
+
entitleUserToProduct: entitleUserToProduct.bind(this),
|
|
56
|
+
unentitleUserToProduct: unentitleUserToProduct.bind(this),
|
|
57
|
+
revokeMicroEntitlementOfAUser: revokeMicroEntitlementOfAUser.bind(this),
|
|
58
|
+
microEntitleUserToProduct: microEntitleUserToProduct.bind(this),
|
|
59
|
+
bulkMicroEntitleProductToUser: bulkMicroEntitleProductToUser.bind(this),
|
|
60
|
+
enrollUserInClass: enrollUserInClass.bind(this),
|
|
61
|
+
getExtProduct: getExtProduct.bind(this),
|
|
62
|
+
getSpaceDetails: getSpaceDetails.bind(this),
|
|
63
|
+
updateUserInformation: updateUserInformation.bind(this),
|
|
64
|
+
updateUserSpace: updateUserSpace.bind(this),
|
|
65
|
+
getInvitationsByEmail: getInvitationsByEmail.bind(this),
|
|
66
|
+
updateInstituteTitle: updateInstituteTitle.bind(this)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Wiki Link for SDK params
|
|
72
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getuserspacesparams
|
|
73
|
+
*/
|
|
74
|
+
function getUserSpaces(options) {
|
|
75
|
+
var self = this;
|
|
76
|
+
// Initializing promise
|
|
77
|
+
var dfd = q.defer();
|
|
78
|
+
// Validations
|
|
79
|
+
|
|
80
|
+
if(options && options.extuserid) {
|
|
81
|
+
// Passed all validations, Contruct API url
|
|
82
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
83
|
+
self.config.AUTH_API_URLS.getUserSpaces;
|
|
84
|
+
url = helpers.api.constructAPIUrl(url, {
|
|
85
|
+
accountid: self.accountId, extuserid: options.extuserid
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
var params = {};
|
|
89
|
+
if(options.spaceRole) { params.spaceRole = options.spaceRole; }
|
|
90
|
+
if(options.spaceType) { params.spaceType = options.spaceType; }
|
|
91
|
+
if(options.spaceOrgContext) { params.spaceOrgContext = options.spaceOrgContext; }
|
|
92
|
+
if(options.details) { params.details = options.details; }
|
|
93
|
+
if(options.cursor) { params.cursor = options.cursor; }
|
|
94
|
+
|
|
95
|
+
// Setup request with URL and Params
|
|
96
|
+
var requestAPI = request.get(url).query(params);
|
|
97
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
98
|
+
|
|
99
|
+
requestAPI.end(function(error, response) {
|
|
100
|
+
if(error) {
|
|
101
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
102
|
+
dfd.reject(err);
|
|
103
|
+
}
|
|
104
|
+
else { dfd.resolve(response.body); }
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
var err = {};
|
|
108
|
+
err.message = err.description = 'extuserid not found in request options.';
|
|
109
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
110
|
+
dfd.reject(err);
|
|
111
|
+
}
|
|
112
|
+
return dfd.promise;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Wiki Link for SDK params
|
|
117
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#validatespacecodeparams
|
|
118
|
+
*/
|
|
119
|
+
function validateSpaceCode(options) {
|
|
120
|
+
var self = this;
|
|
121
|
+
// Initializing promise
|
|
122
|
+
var dfd = q.defer();
|
|
123
|
+
|
|
124
|
+
if(options && options.spaceCodeBody && options.spaceCodeBody.space_code) {
|
|
125
|
+
// Passed all validations, Contruct API url
|
|
126
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
127
|
+
self.config.AUTH_API_URLS.validateSpaceCode;
|
|
128
|
+
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
|
|
129
|
+
|
|
130
|
+
// Setup request with URL and Params
|
|
131
|
+
var requestAPI = request.post(url)
|
|
132
|
+
.set('Content-Type', 'application/json')
|
|
133
|
+
.set('Accept', 'application/json')
|
|
134
|
+
.send(options.spaceCodeBody);
|
|
135
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
136
|
+
|
|
137
|
+
requestAPI.end(function(error, response) {
|
|
138
|
+
if(error) {
|
|
139
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
140
|
+
dfd.reject(err);
|
|
141
|
+
}
|
|
142
|
+
else { dfd.resolve(response.body); }
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
145
|
+
var err = {};
|
|
146
|
+
err.message = err.description = 'spaceCodeBody or space_code not found in request options.';
|
|
147
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
148
|
+
dfd.reject(err);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return dfd.promise;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Wiki Link for SDK params
|
|
156
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#validateclasscodeparams
|
|
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(err);
|
|
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
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Wiki Link for SDK params
|
|
201
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#generatespacecodeparams
|
|
202
|
+
*/
|
|
203
|
+
function generateSpaceCode(options) {
|
|
204
|
+
var self = this;
|
|
205
|
+
|
|
206
|
+
// Initializing promise
|
|
207
|
+
var dfd = q.defer();
|
|
208
|
+
|
|
209
|
+
// Passed all validations, Contruct API url
|
|
210
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
211
|
+
self.config.AUTH_API_URLS.generateSpaceCode;
|
|
212
|
+
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
|
|
213
|
+
|
|
214
|
+
var bodyParams = {};
|
|
215
|
+
if(options.ignore_words) { bodyParams.ignore_words = options.ignore_words; }
|
|
216
|
+
// Setup request with URL and Params
|
|
217
|
+
var requestAPI = request.post(url)
|
|
218
|
+
.set('Content-Type', 'application/json')
|
|
219
|
+
.set('Accept', 'application/json')
|
|
220
|
+
.send(bodyParams);
|
|
221
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
222
|
+
|
|
223
|
+
requestAPI.end(function(error, response) {
|
|
224
|
+
if(error) {
|
|
225
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
226
|
+
dfd.reject(err);
|
|
227
|
+
}
|
|
228
|
+
else { dfd.resolve(response); }
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return dfd.promise;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Wiki Link for SDK params
|
|
236
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#changespacecodeparams
|
|
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(err);
|
|
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
|
+
* Wiki Link for SDK params
|
|
276
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#joininstitutespaceparams
|
|
277
|
+
*/
|
|
278
|
+
function joinInstituteSpace(options) {
|
|
279
|
+
var self = this;
|
|
280
|
+
// Initializing promise
|
|
281
|
+
var dfd = q.defer();
|
|
282
|
+
|
|
283
|
+
if(options && options.ext_user_id &&
|
|
284
|
+
options.ext_role && options.space_code)
|
|
285
|
+
{
|
|
286
|
+
// Passed all validations, Contruct API url
|
|
287
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
288
|
+
self.config.AUTH_API_URLS.joinInstituteSpace;
|
|
289
|
+
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId });
|
|
290
|
+
|
|
291
|
+
// Setup request with URL and Params
|
|
292
|
+
var requestAPI = request.post(url)
|
|
293
|
+
.set('Content-Type', 'application/json')
|
|
294
|
+
.set('Accept', 'application/json')
|
|
295
|
+
.send(options);
|
|
296
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
297
|
+
|
|
298
|
+
requestAPI.end(function(error, response) {
|
|
299
|
+
if(error) {
|
|
300
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
301
|
+
dfd.reject(err);
|
|
302
|
+
}
|
|
303
|
+
else { dfd.resolve(response.body); }
|
|
304
|
+
});
|
|
305
|
+
} else {
|
|
306
|
+
var err = {};
|
|
307
|
+
err.message = err.description = 'ext_user_id or ext_role or space_code not found in request options.';
|
|
308
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
309
|
+
dfd.reject(err);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return dfd.promise;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Wiki Link for SDK params
|
|
317
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#provisionspacestostudentparams
|
|
318
|
+
*/
|
|
319
|
+
function provisionSpacesToStudent(options) {
|
|
320
|
+
var self = this;
|
|
321
|
+
// Initializing promise
|
|
322
|
+
var dfd = q.defer();
|
|
323
|
+
var err = {};
|
|
324
|
+
if(options && options.ext_user_id && options.ext_role) {
|
|
325
|
+
|
|
326
|
+
// Passed all validations, Contruct API url
|
|
327
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
328
|
+
self.config.AUTH_API_URLS.provisionSpacesToStudent;
|
|
329
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
330
|
+
|
|
331
|
+
// Setup request with URL and Params
|
|
332
|
+
var requestAPI = request.post(url)
|
|
333
|
+
.set('Content-Type', 'application/json')
|
|
334
|
+
.set('Accept', 'application/json')
|
|
335
|
+
.send(options);
|
|
336
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
337
|
+
|
|
338
|
+
requestAPI.end(function(error, response) {
|
|
339
|
+
if(error) {
|
|
340
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
341
|
+
dfd.reject(err);
|
|
342
|
+
}
|
|
343
|
+
else { dfd.resolve(response.body); }
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
err.message = err.description = 'ext_user_id or ext_role not found in request options.';
|
|
348
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
349
|
+
dfd.reject(err);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return dfd.promise;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Wiki Link for SDK params
|
|
357
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#provisionspacestoteacherparams
|
|
358
|
+
*/
|
|
359
|
+
function provisionSpacesToTeacher(options) {
|
|
360
|
+
var self = this;
|
|
361
|
+
// Initializing promise
|
|
362
|
+
var dfd = q.defer();
|
|
363
|
+
|
|
364
|
+
if(options && options.ext_user_id && options.ext_role)
|
|
365
|
+
{
|
|
366
|
+
// Passed all validations, Contruct API url
|
|
367
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
368
|
+
self.config.AUTH_API_URLS.provisionSpacesToTeacher;
|
|
369
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
370
|
+
|
|
371
|
+
// Setup request with URL and Params
|
|
372
|
+
var requestAPI = request.post(url)
|
|
373
|
+
.set('Content-Type', 'application/json')
|
|
374
|
+
.set('Accept', 'application/json')
|
|
375
|
+
.send(options);
|
|
376
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
377
|
+
|
|
378
|
+
requestAPI.end(function(error, response) {
|
|
379
|
+
if(error) {
|
|
380
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
381
|
+
dfd.reject(err);
|
|
382
|
+
}
|
|
383
|
+
else { dfd.resolve(response.body); }
|
|
384
|
+
});
|
|
385
|
+
} else {
|
|
386
|
+
var err = {};
|
|
387
|
+
err.message = err.description = 'Mandatory parameters [rxt_user_id, ext_role] not found in request options.';
|
|
388
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
389
|
+
dfd.reject(err);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return dfd.promise;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Wiki Link for SDK params
|
|
397
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#provisionbulkspacesparams
|
|
398
|
+
*/
|
|
399
|
+
function provisionBulkSpaces(options) {
|
|
400
|
+
var self = this;
|
|
401
|
+
// Initializing promise
|
|
402
|
+
var dfd = q.defer();
|
|
403
|
+
// Validations
|
|
404
|
+
var err = helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
405
|
+
if(err) { dfd.reject(err); }
|
|
406
|
+
else {
|
|
407
|
+
if(options && options.users && options.space_title) {
|
|
408
|
+
// Passed all validations, Contruct API url
|
|
409
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
410
|
+
self.config.AUTH_API_URLS.provisionBulkSpaces;
|
|
411
|
+
url = helpers.api.constructAPIUrl(url, { orgId : self.orgId });
|
|
412
|
+
|
|
413
|
+
// Setup request with URL and Params
|
|
414
|
+
var requestAPI = request.post(url)
|
|
415
|
+
.set('Content-Type', 'application/json')
|
|
416
|
+
.set('Accept', 'application/json')
|
|
417
|
+
.send(options);
|
|
418
|
+
|
|
419
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
420
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
421
|
+
|
|
422
|
+
requestAPI.end(function(error, response) {
|
|
423
|
+
if(error) {
|
|
424
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
425
|
+
dfd.reject(err);
|
|
426
|
+
}
|
|
427
|
+
else { dfd.resolve(response.body); }
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
err = {};
|
|
432
|
+
err.message = err.description = 'Mandatory parameters: space_title or users not found in request options.';
|
|
433
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
434
|
+
dfd.reject(err);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return dfd.promise;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Wiki Link for SDK params
|
|
443
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#shadowprovisionparams
|
|
444
|
+
*/
|
|
445
|
+
function shadowProvision(options) {
|
|
446
|
+
var self = this;
|
|
447
|
+
//Initializing promise
|
|
448
|
+
var dfd = q.defer(), err = {};
|
|
449
|
+
//Validations
|
|
450
|
+
if (options && options.ext_user_id && options.ext_role) {
|
|
451
|
+
//Passed all validations, Contruct API url
|
|
452
|
+
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.shadowProvision;
|
|
453
|
+
url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
|
|
454
|
+
|
|
455
|
+
// Setup request with URL and Params
|
|
456
|
+
var requestAPI = request.post(url)
|
|
457
|
+
.set('Content-Type', 'application/json')
|
|
458
|
+
.set('Accept', 'application/json')
|
|
459
|
+
.send(options);
|
|
460
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
461
|
+
|
|
462
|
+
requestAPI
|
|
463
|
+
.agent(keepaliveAgent)
|
|
464
|
+
.end(function (err, response) {
|
|
465
|
+
if (err) {
|
|
466
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
467
|
+
dfd.reject(err);
|
|
468
|
+
}
|
|
469
|
+
else { dfd.resolve(response.body); }
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
err.message = err.description = 'Mandatory parameters: ext_user_id or ext_role not ' +
|
|
474
|
+
'found in request options.';
|
|
475
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
476
|
+
dfd.reject(err);
|
|
477
|
+
}
|
|
478
|
+
return dfd.promise;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Wiki Link for SDK params
|
|
483
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#entitleusertoproductparams
|
|
484
|
+
*/
|
|
485
|
+
function entitleUserToProduct(options) {
|
|
486
|
+
var self = this;
|
|
487
|
+
// Initializing promise
|
|
488
|
+
var dfd = q.defer();
|
|
489
|
+
|
|
490
|
+
if(options && options.ext_user_id &&
|
|
491
|
+
options.ext_role && (options.productcode || options.ext_product_id))
|
|
492
|
+
{
|
|
493
|
+
// Passed all validations, Contruct API url
|
|
494
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
495
|
+
self.config.AUTH_API_URLS.entitleUserToProduct;
|
|
496
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
497
|
+
|
|
498
|
+
// Setup request with URL and Params
|
|
499
|
+
var requestAPI = request.post(url)
|
|
500
|
+
.set('Content-Type', 'application/json')
|
|
501
|
+
.set('Accept', 'application/json')
|
|
502
|
+
.send(options);
|
|
503
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
504
|
+
|
|
505
|
+
requestAPI.end(function(error, response) {
|
|
506
|
+
if(error) {
|
|
507
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
508
|
+
dfd.reject(err);
|
|
509
|
+
}
|
|
510
|
+
else { dfd.resolve(response.body); }
|
|
511
|
+
});
|
|
512
|
+
} else {
|
|
513
|
+
var err = {};
|
|
514
|
+
err.description = 'Missing mandatory keys in request options. \'ext_user_id\', \'ext_role\' and ' +
|
|
515
|
+
'either of \'ext_product_id\' or \'productcode\' must be present.';
|
|
516
|
+
err.message = err.description;
|
|
517
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
518
|
+
dfd.reject(err);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return dfd.promise;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Wiki Link for SDK params
|
|
526
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#unentitleusertoproductparams
|
|
527
|
+
*/
|
|
528
|
+
function unentitleUserToProduct(options) {
|
|
529
|
+
var self = this;
|
|
530
|
+
var dfd = q.defer();
|
|
531
|
+
|
|
532
|
+
if (options && options.ext_user_id && options.productcode && options.ext_actor_id
|
|
533
|
+
&& (options.audit !== undefined)) {
|
|
534
|
+
// Passed all validations, Contruct API url
|
|
535
|
+
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.entitleUserToProduct;
|
|
536
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
537
|
+
|
|
538
|
+
// Setup request with URL and Params
|
|
539
|
+
var requestAPI = request.delete(url)
|
|
540
|
+
.set('Content-Type', 'application/json')
|
|
541
|
+
.set('Accept', 'application/json')
|
|
542
|
+
.send(options);
|
|
543
|
+
|
|
544
|
+
if (self.traceid) {
|
|
545
|
+
requestAPI.set('X-Amzn-Trace-Id', self.traceid);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
requestAPI.end(function(error, response) {
|
|
549
|
+
if (error) {
|
|
550
|
+
var err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
551
|
+
dfd.reject(err);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
dfd.resolve(response.body);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
} else {
|
|
558
|
+
var err = {};
|
|
559
|
+
err.message = err.description = 'Missing mandatory keys in request options.' +
|
|
560
|
+
' \'ext_user_id\', \'ext_actor_id\', \'productcode\' and \'audit\'' +
|
|
561
|
+
' must be present';
|
|
562
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
563
|
+
|
|
564
|
+
dfd.reject(err);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return dfd.promise;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Wiki Link for SDK params
|
|
572
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#microentitleusertoproductparams
|
|
573
|
+
*/
|
|
574
|
+
function microEntitleUserToProduct(options) {
|
|
575
|
+
var self = this;
|
|
576
|
+
// Initializing promise
|
|
577
|
+
var dfd = q.defer();
|
|
578
|
+
var bValidOptions = true;
|
|
579
|
+
var err = {
|
|
580
|
+
description: '',
|
|
581
|
+
message: ''
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
if (!(options && options.ext_user_id && options.context && options.feature_key &&
|
|
585
|
+
options.feature_id)) {
|
|
586
|
+
bValidOptions = false;
|
|
587
|
+
err.description = 'ext_user_id or context or feature_key or feature_id ' +
|
|
588
|
+
'not found in request options. ';
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (bValidOptions && (options.productcode || options.ext_product_id)) {
|
|
592
|
+
// Passed all validations, Contruct API url
|
|
593
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
594
|
+
self.config.AUTH_API_URLS.microEntitleUserToProduct;
|
|
595
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
596
|
+
|
|
597
|
+
// Setup request with URL and Params
|
|
598
|
+
var requestAPI = request.post(url)
|
|
599
|
+
.set('Content-Type', 'application/json')
|
|
600
|
+
.set('Accept', 'application/json')
|
|
601
|
+
.send(options);
|
|
602
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
603
|
+
|
|
604
|
+
requestAPI.end(function(error, response) {
|
|
605
|
+
if(error) {
|
|
606
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
607
|
+
dfd.reject(err);
|
|
608
|
+
}
|
|
609
|
+
else { dfd.resolve(response.body); }
|
|
610
|
+
});
|
|
611
|
+
} else {
|
|
612
|
+
if(!(options.productcode || options.ext_product_id)) {
|
|
613
|
+
err.description += 'Either of ext_product_id or productcode must be ' +
|
|
614
|
+
'present in request options.';
|
|
615
|
+
}
|
|
616
|
+
err.message = err.description;
|
|
617
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
618
|
+
dfd.reject(err);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return dfd.promise;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Wiki Link for SDK params
|
|
626
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#bulkmicroentitleproducttouserparams
|
|
627
|
+
*/
|
|
628
|
+
function bulkMicroEntitleProductToUser(options) {
|
|
629
|
+
var self = this;
|
|
630
|
+
// Initializing promise
|
|
631
|
+
var dfd = q.defer();
|
|
632
|
+
|
|
633
|
+
if(options && options['micro-entitlements'])
|
|
634
|
+
{
|
|
635
|
+
// Passed all validations, Contruct API url
|
|
636
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
637
|
+
self.config.AUTH_API_URLS.bulkMicroEntitleProductToUser;
|
|
638
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
639
|
+
|
|
640
|
+
// Setup request with URL and Params
|
|
641
|
+
var requestAPI = request.post(url)
|
|
642
|
+
.set('Content-Type', 'application/json')
|
|
643
|
+
.set('Accept', 'application/json')
|
|
644
|
+
.send(options);
|
|
645
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
646
|
+
|
|
647
|
+
requestAPI.end(function(error, response) {
|
|
648
|
+
if(error) {
|
|
649
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
650
|
+
dfd.reject(err);
|
|
651
|
+
}
|
|
652
|
+
else { dfd.resolve(response.body); }
|
|
653
|
+
});
|
|
654
|
+
} else {
|
|
655
|
+
var err = {};
|
|
656
|
+
err.description = 'Missing mandatory keys in request options.' +
|
|
657
|
+
' \'micro-entitlements\' must be present.';
|
|
658
|
+
err.message = err.description;
|
|
659
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
660
|
+
dfd.reject(err);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
return dfd.promise;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Wiki Link for SDK params
|
|
668
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#revokemicroentitlementofauserparams
|
|
669
|
+
*/
|
|
670
|
+
function revokeMicroEntitlementOfAUser(options) {
|
|
671
|
+
var self = this;
|
|
672
|
+
// Initializing promise
|
|
673
|
+
var dfd = q.defer();
|
|
674
|
+
var err = {
|
|
675
|
+
description: '',
|
|
676
|
+
message: ''
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
if((options && options.ext_user_id && options.context && options.feature_key &&
|
|
680
|
+
options.ext_actor_id && (options.audit !== undefined) &&
|
|
681
|
+
(options.productcode || options.ext_product_id))) {
|
|
682
|
+
// Passed all validations, Contruct API url
|
|
683
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
684
|
+
self.config.AUTH_API_URLS.microEntitleUserToProduct;
|
|
685
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
686
|
+
|
|
687
|
+
// Setup request with URL and Params
|
|
688
|
+
var requestAPI = request.delete(url)
|
|
689
|
+
.set('Content-Type', 'application/json')
|
|
690
|
+
.set('Accept', 'application/json')
|
|
691
|
+
.send(options);
|
|
692
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
693
|
+
|
|
694
|
+
requestAPI.end(function(error, response) {
|
|
695
|
+
if(error) {
|
|
696
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
697
|
+
dfd.reject(err);
|
|
698
|
+
}
|
|
699
|
+
else { dfd.resolve(response.body); }
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
err.description = 'ext_user_id or context or feature_key or ext_actor_id or audit field ' +
|
|
704
|
+
'not found or is empty in request options. Either productcode or ' +
|
|
705
|
+
'ext_product_id must be provided.';
|
|
706
|
+
err.message = err.description;
|
|
707
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
708
|
+
dfd.reject(err);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return dfd.promise;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Wiki Link for SDK params
|
|
716
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getextproductparams
|
|
717
|
+
*/
|
|
718
|
+
function getExtProduct(options) {
|
|
719
|
+
var self = this;
|
|
720
|
+
// Initializing promise
|
|
721
|
+
var dfd = q.defer();
|
|
722
|
+
|
|
723
|
+
if(options && options.ext_product_id)
|
|
724
|
+
{
|
|
725
|
+
// Passed all validations, Contruct API url
|
|
726
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
727
|
+
self.config.AUTH_API_URLS.getExtProductAPI;
|
|
728
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, extProductId: options.ext_product_id});
|
|
729
|
+
|
|
730
|
+
// Setup request with URL and Params
|
|
731
|
+
var requestAPI = request.get(url);
|
|
732
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
733
|
+
|
|
734
|
+
requestAPI.end(function(error, response) {
|
|
735
|
+
if(error) {
|
|
736
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
737
|
+
dfd.reject(err);
|
|
738
|
+
}
|
|
739
|
+
else { dfd.resolve(response.body); }
|
|
740
|
+
});
|
|
741
|
+
} else {
|
|
742
|
+
var err = {};
|
|
743
|
+
err.message = err.description = 'ext_product_id not found in request options.';
|
|
744
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
745
|
+
dfd.reject(err);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
return dfd.promise;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Wiki Link for SDK params
|
|
753
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getspacedetailsparams
|
|
754
|
+
*/
|
|
755
|
+
function getSpaceDetails(options) {
|
|
756
|
+
var self = this;
|
|
757
|
+
// Initializing promise
|
|
758
|
+
var dfd = q.defer();
|
|
759
|
+
|
|
760
|
+
if(options && options.spacekey) {
|
|
761
|
+
// Passed all validations, Contruct API url
|
|
762
|
+
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getSpaceDetails;
|
|
763
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId, spacekey: options.spacekey});
|
|
764
|
+
|
|
765
|
+
var params = { orgid: self.orgId };
|
|
766
|
+
|
|
767
|
+
// Setup request with URL and Params
|
|
768
|
+
var requestAPI = request.get(url).query(params);
|
|
769
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
770
|
+
|
|
771
|
+
// Setup token in Authorization header
|
|
772
|
+
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
773
|
+
|
|
774
|
+
requestAPI.end(function(error, response) {
|
|
775
|
+
if(error) {
|
|
776
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
777
|
+
dfd.reject(err);
|
|
778
|
+
}
|
|
779
|
+
else { dfd.resolve(response.body); }
|
|
780
|
+
});
|
|
781
|
+
} else {
|
|
782
|
+
var err = {};
|
|
783
|
+
err.message = err.description = 'spacekey not found in request options.';
|
|
784
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
785
|
+
dfd.reject(err);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
return dfd.promise;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Wiki Link for SDK params
|
|
793
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#enrolluserinclassparams
|
|
794
|
+
*/
|
|
795
|
+
function enrollUserInClass(options) {
|
|
796
|
+
var self = this;
|
|
797
|
+
// Initializing promise
|
|
798
|
+
var dfd = q.defer();
|
|
799
|
+
|
|
800
|
+
if(options && options.ext_user_id &&
|
|
801
|
+
options.ext_role && options.class_code)
|
|
802
|
+
{
|
|
803
|
+
// Passed all validations, Contruct API url
|
|
804
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
805
|
+
self.config.AUTH_API_URLS.enrollUserInClass;
|
|
806
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
807
|
+
|
|
808
|
+
// Setup request with URL and Params
|
|
809
|
+
var requestAPI = request.post(url)
|
|
810
|
+
.set('Content-Type', 'application/json')
|
|
811
|
+
.set('Accept', 'application/json')
|
|
812
|
+
.send(options);
|
|
813
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
814
|
+
|
|
815
|
+
requestAPI.end(function(error, response) {
|
|
816
|
+
if(error) {
|
|
817
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
818
|
+
dfd.reject(err);
|
|
819
|
+
}
|
|
820
|
+
else { dfd.resolve(response.body); }
|
|
821
|
+
});
|
|
822
|
+
} else {
|
|
823
|
+
var err = {};
|
|
824
|
+
err.message = err.description = 'ext_user_id or ext_role or class_code not found in request options.';
|
|
825
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
826
|
+
dfd.reject(err);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
return dfd.promise;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Wiki Link for SDK params
|
|
834
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#updateuserinformationparams
|
|
835
|
+
*/
|
|
836
|
+
function updateUserInformation(options) {
|
|
837
|
+
var self = this;
|
|
838
|
+
// Initializing promise
|
|
839
|
+
var dfd = q.defer(), err = {};
|
|
840
|
+
|
|
841
|
+
if(options && options.ext_user_id)
|
|
842
|
+
{
|
|
843
|
+
// Passed all validations, Contruct API url
|
|
844
|
+
var url = self.config.DEFAULT_HOSTS.AUTH +
|
|
845
|
+
self.config.AUTH_API_URLS.updateUserInformation;
|
|
846
|
+
url = helpers.api.constructAPIUrl(url, { accountId : self.accountId });
|
|
847
|
+
var bodyParams = {
|
|
848
|
+
ext_user_id: options.ext_user_id
|
|
849
|
+
};
|
|
850
|
+
if(options.ref_id) { bodyParams.ref_id = options.ref_id; }
|
|
851
|
+
if(options.ext_email) { bodyParams.ext_email = options.ext_email; }
|
|
852
|
+
if(options.ext_first_name) { bodyParams.ext_first_name = options.ext_first_name; }
|
|
853
|
+
if(options.ext_last_name) { bodyParams.ext_last_name = options.ext_last_name; }
|
|
854
|
+
if(options.address) { bodyParams.address = options.address; }
|
|
855
|
+
// Setup request with URL and Params
|
|
856
|
+
var requestAPI = request.put(url)
|
|
857
|
+
.set('Content-Type', 'application/json')
|
|
858
|
+
.set('Accept', 'application/json')
|
|
859
|
+
.send(bodyParams);
|
|
860
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
861
|
+
|
|
862
|
+
requestAPI.end(function(error, response) {
|
|
863
|
+
if(error) {
|
|
864
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
865
|
+
dfd.reject(err);
|
|
866
|
+
}
|
|
867
|
+
else { dfd.resolve(response.body); }
|
|
868
|
+
});
|
|
869
|
+
} else {
|
|
870
|
+
err.message = err.description = 'Mandatory parameters not found in request options:' +
|
|
871
|
+
' ["ext_user_id"]';
|
|
872
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
873
|
+
dfd.reject(err);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
return dfd.promise;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Wiki Link for SDK params
|
|
881
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#updateuserspaceparams
|
|
882
|
+
*/
|
|
883
|
+
function updateUserSpace(options) {
|
|
884
|
+
var self = this;
|
|
885
|
+
|
|
886
|
+
// Initializing promise
|
|
887
|
+
var deferred = q.defer();
|
|
888
|
+
var error;
|
|
889
|
+
|
|
890
|
+
// Validate request input.
|
|
891
|
+
if (options && options.extuserid && options.spacekey && options.body) {
|
|
892
|
+
// Passed all validations, Contruct API url
|
|
893
|
+
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.updateUserSpace;
|
|
894
|
+
url = helpers.api.constructAPIUrl(url, { accountid : self.accountId, extuserid: options.extuserid, spacekey: options.spacekey });
|
|
895
|
+
|
|
896
|
+
// Setup request with URL and Params
|
|
897
|
+
var requestAPI = request.put(url)
|
|
898
|
+
.set('Content-Type', 'application/json')
|
|
899
|
+
.set('Accept', 'application/json')
|
|
900
|
+
.send(options.body);
|
|
901
|
+
|
|
902
|
+
// Add 'trace_id' to the request headers.
|
|
903
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
904
|
+
|
|
905
|
+
requestAPI
|
|
906
|
+
.agent(keepaliveAgent)
|
|
907
|
+
.end(function(err, response) {
|
|
908
|
+
if (err) {
|
|
909
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
910
|
+
deferred.reject(error);
|
|
911
|
+
} else {
|
|
912
|
+
deferred.resolve(response.body);
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
} else {
|
|
916
|
+
var err = {};
|
|
917
|
+
err.message = err.description = 'Missing mandatory params: \'extuserid\' or \'spacekey\' or \'body\' not found in the request options.';
|
|
918
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
919
|
+
deferred.reject(error);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
return deferred.promise;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Wiki Link for SDK params
|
|
927
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#getinvitationsbyemailparams
|
|
928
|
+
*/
|
|
929
|
+
function getInvitationsByEmail(options) {
|
|
930
|
+
var self = this;
|
|
931
|
+
// Initializing promise
|
|
932
|
+
var dfd = q.defer();
|
|
933
|
+
var err = {};
|
|
934
|
+
if (options && options.email) {
|
|
935
|
+
|
|
936
|
+
// Passed all validations, Contruct API url
|
|
937
|
+
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.getInvitationsByEmail;
|
|
938
|
+
url = helpers.api.constructAPIUrl(url, { accountid: self.accountId });
|
|
939
|
+
|
|
940
|
+
var queryParam = { email: options.email };
|
|
941
|
+
if (options.status) { queryParam.status = options.status; }
|
|
942
|
+
|
|
943
|
+
// Setup request with URL and Params
|
|
944
|
+
var requestAPI = request.get(url).query(queryParam);
|
|
945
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
946
|
+
|
|
947
|
+
requestAPI.end(function (error, response) {
|
|
948
|
+
if (error) {
|
|
949
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
950
|
+
dfd.reject(err);
|
|
951
|
+
}
|
|
952
|
+
else { dfd.resolve(response.body); }
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
err.message = err.description = 'email not found in request options.';
|
|
957
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
958
|
+
dfd.reject(err);
|
|
959
|
+
}
|
|
960
|
+
return dfd.promise;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Wiki Link for SDK params
|
|
965
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/18_Spaces-Adapter#updateinstitutetitleparams
|
|
966
|
+
*/
|
|
967
|
+
function updateInstituteTitle(options){
|
|
968
|
+
var self = this;
|
|
969
|
+
// Initializing promise
|
|
970
|
+
var dfd = q.defer();
|
|
971
|
+
var err = {};
|
|
972
|
+
if (options && options.space_code && options.body && options.body.ext_actor_id ) {
|
|
973
|
+
// Passed all validations, Contruct API url
|
|
974
|
+
var url = self.config.DEFAULT_HOSTS.AUTH + self.config.AUTH_API_URLS.updateInstituteTitle;
|
|
975
|
+
url = helpers.api.constructAPIUrl(url,
|
|
976
|
+
{ accountId: self.accountId, instituteSpaceCode: options.space_code });
|
|
977
|
+
|
|
978
|
+
// Setup request with URL and Params
|
|
979
|
+
var requestAPI = request.put(url)
|
|
980
|
+
.set('Content-Type', 'application/json')
|
|
981
|
+
.set('Accept', 'application/json')
|
|
982
|
+
.send(options.body);
|
|
983
|
+
if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
984
|
+
|
|
985
|
+
requestAPI.end(function (error, response) {
|
|
986
|
+
if (error) {
|
|
987
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
988
|
+
dfd.reject(err);
|
|
989
|
+
}
|
|
990
|
+
else { dfd.resolve(response.body); }
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
err.message = err.description = 'space_code or ext_actor_id not found in request options.';
|
|
995
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
996
|
+
dfd.reject(err);
|
|
997
|
+
}
|
|
998
|
+
return dfd.promise;
|
|
999
|
+
}
|