comprodls-sdk 2.54.2 → 2.55.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.
- package/dist/comprodls-sdk.js +2365 -17280
- package/dist/comprodls-sdk.min.js +15 -20
- package/lib/comprodls.js +0 -2
- package/lib/config/index.js +2 -1
- package/lib/services/drive/index.js +188 -1
- package/package.json +1 -2
- package/lib/services/lrs/index.js +0 -459
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
/*************************************************************************
|
|
2
|
-
*
|
|
3
|
-
* COMPRO CONFIDENTIAL
|
|
4
|
-
* __________________
|
|
5
|
-
*
|
|
6
|
-
* [2015] - [2020] Compro Technologies Private Limited
|
|
7
|
-
* All Rights Reserved.
|
|
8
|
-
*
|
|
9
|
-
* NOTICE: All information contained herein is, and remains
|
|
10
|
-
* the property of Compro Technologies Private Limited. The
|
|
11
|
-
* intellectual and technical concepts contained herein are
|
|
12
|
-
* proprietary to Compro Technologies Private Limited and may
|
|
13
|
-
* be covered by U.S. and Foreign Patents, patents in process,
|
|
14
|
-
* and are protected by trade secret or copyright law.
|
|
15
|
-
*
|
|
16
|
-
* Dissemination of this information or reproduction of this material
|
|
17
|
-
* is strictly forbidden unless prior written permission is obtained
|
|
18
|
-
* from Compro Technologies Pvt. Ltd..
|
|
19
|
-
***************************************************************************/
|
|
20
|
-
/***********************************************************
|
|
21
|
-
* comproDLS SDK Product API Adaptor
|
|
22
|
-
* Functions for calling Product API.
|
|
23
|
-
************************************************************/
|
|
24
|
-
var TinCan = require('tincanjs');
|
|
25
|
-
var q = require('q');
|
|
26
|
-
|
|
27
|
-
var helpers = require('../../helpers');
|
|
28
|
-
var DLSError = helpers.errors.DLSError;
|
|
29
|
-
|
|
30
|
-
/*********************************
|
|
31
|
-
* Setting Up Module Entry Point
|
|
32
|
-
**********************************/
|
|
33
|
-
module.exports = lrs;
|
|
34
|
-
|
|
35
|
-
function lrs() {
|
|
36
|
-
var error = {};
|
|
37
|
-
//Initializing promise
|
|
38
|
-
try {
|
|
39
|
-
this.lrs = new TinCan.LRS({
|
|
40
|
-
endpoint: this.config.DEFAULT_HOSTS.XAPI + '/' + this.orgId + '/tapi',
|
|
41
|
-
auth: this.token.access_token,
|
|
42
|
-
allowFail: false
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
this.tincan = new TinCan({
|
|
46
|
-
recordStores: [this.lrs]
|
|
47
|
-
});
|
|
48
|
-
} catch (err) {
|
|
49
|
-
err.description = 'Error while initializing lrs.';
|
|
50
|
-
err.message = err.description;
|
|
51
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
52
|
-
return err;
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
"getStatement": getStatement.bind(this),
|
|
56
|
-
"createStatement": createStatement.bind(this)
|
|
57
|
-
/*"setState": setState.bind(this),
|
|
58
|
-
"getState": getState.bind(this),
|
|
59
|
-
"deleteState": deleteState.bind(this)*/
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/*********************************
|
|
64
|
-
* Public Function definitions
|
|
65
|
-
**********************************/
|
|
66
|
-
|
|
67
|
-
//options = {
|
|
68
|
-
// verb: {object} - (Optional) Verb / Action performed by the acting person.
|
|
69
|
-
// actor: {object} - (Optional) The acting person.
|
|
70
|
-
// since: {String} - (Optional) <ISO-8601> date time,
|
|
71
|
-
// until: {String} - (Optional) <ISO-8601> date time,
|
|
72
|
-
// limit: {Number} - (Optional) limit of documents per function call
|
|
73
|
-
// registration: {String} - (Optional) product to which the actor is entitled.
|
|
74
|
-
// moreUrl: {String} - (Optional) Endpoint to get the next set of statements.
|
|
75
|
-
//}
|
|
76
|
-
function getStatement(options) {
|
|
77
|
-
var self = this;
|
|
78
|
-
|
|
79
|
-
//Initializing promise
|
|
80
|
-
var dfd = q.defer(), params = {}, bMoreUrl = false;
|
|
81
|
-
/*var supportedVerbs = ['attempted', 'scored', 'started', 'launched',
|
|
82
|
-
'answered', 'closed', 'terminated'];*/
|
|
83
|
-
if(options) {
|
|
84
|
-
params = {
|
|
85
|
-
limit: options.limit || 10,
|
|
86
|
-
since: options.since || null,
|
|
87
|
-
until: options.until || null
|
|
88
|
-
};
|
|
89
|
-
if(options.actor) { params.agent = new TinCan.Agent(options.actor); }
|
|
90
|
-
if(options.verb) { params.verb = new TinCan.Verb(options.verb); }
|
|
91
|
-
if(options.moreUrl) { bMoreUrl = true; }
|
|
92
|
-
if(options.registration) { params.registration = options.registration; }
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if(bMoreUrl) {
|
|
96
|
-
self.lrs.moreStatements({
|
|
97
|
-
url: options.moreUrl,
|
|
98
|
-
callback: function (err, sr) {
|
|
99
|
-
if (err !== null) {
|
|
100
|
-
var error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
101
|
-
dfd.reject(error);
|
|
102
|
-
} else {
|
|
103
|
-
var statementsArray = [];
|
|
104
|
-
for(var i in sr.statements) {
|
|
105
|
-
statementsArray.push(JSON.parse(sr.statements[i].originalJSON));
|
|
106
|
-
}
|
|
107
|
-
sr.statements = statementsArray;
|
|
108
|
-
dfd.resolve(sr);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
} else {
|
|
113
|
-
self.lrs.queryStatements({
|
|
114
|
-
params: params,
|
|
115
|
-
callback: function (err, sr) {
|
|
116
|
-
if (err !== null) {
|
|
117
|
-
var error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
118
|
-
dfd.reject(error);
|
|
119
|
-
} else {
|
|
120
|
-
var statementsArray = [];
|
|
121
|
-
for(var i in sr.statements) {
|
|
122
|
-
statementsArray.push(JSON.parse(sr.statements[i].originalJSON));
|
|
123
|
-
}
|
|
124
|
-
sr.statements = statementsArray;
|
|
125
|
-
dfd.resolve(sr);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return dfd.promise;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
//options = [{
|
|
136
|
-
// verb: {object} - (Required) Verb / Action performed by the acting person.
|
|
137
|
-
// actor: {object} - (Required) The acting person.
|
|
138
|
-
// object: {object} - (Required) The activity on which the statement is performed. Ref - http://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Activity.html
|
|
139
|
-
// registration: {String} - (Required) Product the actor is entitled to.
|
|
140
|
-
// timestamp: {ISO8601 Date/time value} - (Optional) Time string
|
|
141
|
-
// result: {TinCAN Result} - http://rusticisoftware.github.io/TinCanJS/doc/api/latest/classes/TinCan.Result.html
|
|
142
|
-
//}]
|
|
143
|
-
function createStatement(options) {
|
|
144
|
-
var self = this;
|
|
145
|
-
//Initializing promise
|
|
146
|
-
var dfd = q.defer(), error;
|
|
147
|
-
var createStatementObject = {}, createStatementsArray = [];
|
|
148
|
-
if(Array.isArray(options)) {
|
|
149
|
-
for(var i in options) {
|
|
150
|
-
if (!(options[i].actor && options[i].verb && options[i].object &&
|
|
151
|
-
options[i].registration))
|
|
152
|
-
{
|
|
153
|
-
error = {};
|
|
154
|
-
error.message = error.description = 'Mandatory parameter options' +
|
|
155
|
-
' not found in request options';
|
|
156
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
157
|
-
} else {
|
|
158
|
-
createStatementObject = {
|
|
159
|
-
verb: new TinCan.Verb(options[i].verb), actor: new TinCan.Agent(options[i].actor),
|
|
160
|
-
object: new TinCan.Activity(options[i].object), context: { registration: options[i].registration }
|
|
161
|
-
};
|
|
162
|
-
if(options[i].timestamp) {
|
|
163
|
-
createStatementObject.timestamp = options[i].timestamp;
|
|
164
|
-
}
|
|
165
|
-
if(options[i].result) {
|
|
166
|
-
createStatementObject.result = options[i].result;
|
|
167
|
-
}
|
|
168
|
-
createStatementsArray.push(createStatementObject);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
} else {
|
|
172
|
-
error = {};
|
|
173
|
-
error.message = error.description = 'Mandatory parameter options' +
|
|
174
|
-
' not found in request options';
|
|
175
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
176
|
-
}
|
|
177
|
-
if(error) {
|
|
178
|
-
dfd.reject(error);
|
|
179
|
-
} else {
|
|
180
|
-
self.tincan.sendStatements(
|
|
181
|
-
createStatementsArray,
|
|
182
|
-
function (err) {
|
|
183
|
-
for(var i in err) {
|
|
184
|
-
if(err[i].err !== null) {
|
|
185
|
-
var errObj = {
|
|
186
|
-
message: err[i].xhr.statusText,
|
|
187
|
-
description: JSON.parse(err[i].xhr.response),
|
|
188
|
-
status: err[i].xhr.status
|
|
189
|
-
};
|
|
190
|
-
if(errObj) {
|
|
191
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, errObj);
|
|
192
|
-
dfd.reject(error);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!error) { dfd.resolve(); }
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return dfd.promise;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//options = {
|
|
208
|
-
// email: {String} - (Required) Email address of acting person,
|
|
209
|
-
// verb: {String} - (Required) Verb / Action performed by the acting person. Supported verbs are
|
|
210
|
-
// ['attempted', 'scored', 'started', 'launched', 'answered', 'closed', 'terminated'],
|
|
211
|
-
// itemcode: {String} - (Required) - Item code of the item that the user is acting on.
|
|
212
|
-
// productid: {String} - (Required) - Product to which the acting user is entitled.
|
|
213
|
-
// classid: {String} - (Optional) - Class in which the acting user is enrolled.
|
|
214
|
-
//}
|
|
215
|
-
|
|
216
|
-
/*function createStatement1(options) {
|
|
217
|
-
var self = this;
|
|
218
|
-
|
|
219
|
-
//Initializing promise
|
|
220
|
-
var dfd = q.defer(), error;
|
|
221
|
-
|
|
222
|
-
if (options && options.email && options.verb && options.itemcode &&
|
|
223
|
-
options.productid) {
|
|
224
|
-
var createStatementObject = {};
|
|
225
|
-
var supportedVerbs = ['attempted', 'scored', 'started', 'launched',
|
|
226
|
-
'answered', 'closed', 'terminated'];
|
|
227
|
-
for (var field in options) {
|
|
228
|
-
if (options[field]) {
|
|
229
|
-
switch (field) {
|
|
230
|
-
case 'email':
|
|
231
|
-
createStatementObject.actor = { mbox: 'mailto:' + options[field] };
|
|
232
|
-
break;
|
|
233
|
-
case 'verb':
|
|
234
|
-
if (supportedVerbs.indexOf(options[field]) > -1) {
|
|
235
|
-
createStatementObject.verb = {
|
|
236
|
-
id: 'http://adlnet.gov/expapi/verbs/' + options[field]
|
|
237
|
-
};
|
|
238
|
-
} else {
|
|
239
|
-
error = {};
|
|
240
|
-
error.message = 'Verb: ' + options[field] + ' is not supported.';
|
|
241
|
-
error.description = error.message;
|
|
242
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
243
|
-
dfd.reject(error);
|
|
244
|
-
}
|
|
245
|
-
break;
|
|
246
|
-
case 'itemcode':
|
|
247
|
-
createStatementObject.target = {
|
|
248
|
-
id: self.config.DEFAULT_HOSTS.PRODUCT + '/product/' +
|
|
249
|
-
options.productid + '/' + encodeURIComponent(options[field])
|
|
250
|
-
};
|
|
251
|
-
break;
|
|
252
|
-
case 'productid':
|
|
253
|
-
createStatementObject.context = { productid: options[field] };
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
if(error) { break; }
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
createStatementObject = new TinCan.Statement(createStatementObject);
|
|
261
|
-
|
|
262
|
-
if(!error) {
|
|
263
|
-
self.tincan.sendStatements(
|
|
264
|
-
[createStatementObject],
|
|
265
|
-
function (err) {
|
|
266
|
-
err = err[0];
|
|
267
|
-
if (err.err !== null) {
|
|
268
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
269
|
-
dfd.reject(error);
|
|
270
|
-
} else {
|
|
271
|
-
dfd.resolve();
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
} else {
|
|
277
|
-
error = {};
|
|
278
|
-
error.message = error.description = 'Mandatory parameter options' +
|
|
279
|
-
' not found in request options';
|
|
280
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
281
|
-
dfd.reject(error);
|
|
282
|
-
}
|
|
283
|
-
return dfd.promise;
|
|
284
|
-
}*/
|
|
285
|
-
|
|
286
|
-
//options = {
|
|
287
|
-
// verb: {object} - (Optional) Verb / Action performed by the acting person. Supported verbs are
|
|
288
|
-
// ['attempted', 'scored', 'started', 'launched', 'answered', 'closed', 'terminated'],
|
|
289
|
-
// since: {String} - (Optional) <ISO-8601> date time,
|
|
290
|
-
// until: {String} - (Optional) <ISO-8601> date time,
|
|
291
|
-
// cursor: {String} - (Optional) cursor to next set of documents
|
|
292
|
-
// limit: {String} - (Optional) limit of documents per function call
|
|
293
|
-
//}
|
|
294
|
-
|
|
295
|
-
/*function getStatement1(options) {
|
|
296
|
-
var self = this;
|
|
297
|
-
|
|
298
|
-
//Initializing promise
|
|
299
|
-
var dfd = q.defer(), error, params = {};
|
|
300
|
-
var supportedVerbs = ['attempted', 'scored', 'started', 'launched',
|
|
301
|
-
'answered', 'closed', 'terminated'];
|
|
302
|
-
if(options) {
|
|
303
|
-
params = {
|
|
304
|
-
limit: options.limit || 10,
|
|
305
|
-
since: options.since || null,
|
|
306
|
-
until: options.until || null
|
|
307
|
-
};
|
|
308
|
-
if(options.actor) {
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
if(options.verb) {
|
|
312
|
-
params.verb = options.verb;
|
|
313
|
-
if (supportedVerbs.indexOf(options.verb) > -1) {
|
|
314
|
-
params.verb = new TinCan.Verb({
|
|
315
|
-
id: 'http://adlnet.gov/expapi/verbs/' + options.verb
|
|
316
|
-
});
|
|
317
|
-
} else {
|
|
318
|
-
error= {};
|
|
319
|
-
error.message = 'Verb: ' + options.verb + ' is not supported.';
|
|
320
|
-
error.description = error.message;
|
|
321
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
322
|
-
dfd.reject(error);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if(!error) {
|
|
328
|
-
self.lrs.queryStatements({
|
|
329
|
-
params: params,
|
|
330
|
-
callback: function (err, sr) {
|
|
331
|
-
if (err !== null) {
|
|
332
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
333
|
-
dfd.reject(error);
|
|
334
|
-
} else {
|
|
335
|
-
dfd.resolve(sr);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
return dfd.promise;
|
|
341
|
-
}*/
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
//options = {
|
|
345
|
-
// key: {string} - (Required)
|
|
346
|
-
// email: {String} - (Required) Email address of acting person,
|
|
347
|
-
// itemcode: {String} - (Required) - Item code of the item that the user is acting on.
|
|
348
|
-
// productid: {String} - (Required) - Product to which acting user is entitled.
|
|
349
|
-
/*function getState(options) {
|
|
350
|
-
var self = this;
|
|
351
|
-
|
|
352
|
-
//Initializing promise
|
|
353
|
-
var dfd = q.defer(), error;
|
|
354
|
-
|
|
355
|
-
if (options && options.email && options.verb && options.itemcode &&
|
|
356
|
-
options.productid)
|
|
357
|
-
{
|
|
358
|
-
var agent = new TinCan.Agent({ mbox: 'mailto:' + options.email });
|
|
359
|
-
var activity = new TinCan.Activity({
|
|
360
|
-
id: self.config.DEFAULT_HOSTS.PRODUCT + '/product/' + options.productid +
|
|
361
|
-
'/' + encodeURIComponent(options.itemcode)
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
if(!error) {
|
|
365
|
-
self.tincan.getState (options.key, {
|
|
366
|
-
agent: agent,
|
|
367
|
-
activity: activity,
|
|
368
|
-
callback: function (err, sr) {
|
|
369
|
-
if (err !== null) {
|
|
370
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
371
|
-
dfd.reject(error);
|
|
372
|
-
} else {
|
|
373
|
-
dfd.resolve(sr);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
error = {};
|
|
380
|
-
error.message = error.description = 'Mandatory parameter options' +
|
|
381
|
-
' not found in request options';
|
|
382
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
383
|
-
dfd.reject(error);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return dfd.promise;
|
|
387
|
-
}*/
|
|
388
|
-
|
|
389
|
-
//options = {
|
|
390
|
-
// key: {string}
|
|
391
|
-
// email: {String} - (Required) Email address of acting person,
|
|
392
|
-
// itemcode: {String} - (Required) - Item code of the item that the user is acting on.
|
|
393
|
-
// productid: {String} - (Required) - Product to which the acting user is entitled.
|
|
394
|
-
|
|
395
|
-
/*function setState(options) {
|
|
396
|
-
var self = this;
|
|
397
|
-
|
|
398
|
-
//Initializing promise
|
|
399
|
-
var dfd = q.defer(), error;
|
|
400
|
-
|
|
401
|
-
if (options && options.email && options.itemcode && options.productid) {
|
|
402
|
-
self.tincan.setState(options.key, options.value, {
|
|
403
|
-
agent: new TinCan.Agent({ mbox: options.email }),
|
|
404
|
-
activity: new TinCan.Agent({
|
|
405
|
-
id: self.config.DEFAULT_HOSTS.PRODUCT + '/product/' +
|
|
406
|
-
options.productid + '/' +
|
|
407
|
-
encodeURIComponent(options.itemcode)
|
|
408
|
-
}),
|
|
409
|
-
function (err) {
|
|
410
|
-
err = err[0];
|
|
411
|
-
if (err.err !== null) {
|
|
412
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
413
|
-
dfd.reject(error);
|
|
414
|
-
} else {
|
|
415
|
-
dfd.resolve();
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
} else {
|
|
420
|
-
error.message = error.description = 'Mandatory parameter options,' +
|
|
421
|
-
' email, itemcode, productidnot found in request options';
|
|
422
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, error);
|
|
423
|
-
dfd.reject(error);
|
|
424
|
-
}
|
|
425
|
-
return dfd.promise;
|
|
426
|
-
}*/
|
|
427
|
-
|
|
428
|
-
//options = {
|
|
429
|
-
// key: {string}
|
|
430
|
-
// email: {String} - (Required) Email address of acting person,
|
|
431
|
-
// itemcode: {String} - (Required) - Item code of the item that the user is acting on.
|
|
432
|
-
//}
|
|
433
|
-
|
|
434
|
-
/*function deleteState (options) {
|
|
435
|
-
|
|
436
|
-
var self = this;
|
|
437
|
-
|
|
438
|
-
//Initializing promise
|
|
439
|
-
var dfd = q.defer(), error;
|
|
440
|
-
var agent = new TinCan.Agent({ mbox: options.email });
|
|
441
|
-
var activity = new TinCan.Agent({ id: options.itemcode });
|
|
442
|
-
|
|
443
|
-
if(!error) {
|
|
444
|
-
self.tincan.deleteState(options.key, {
|
|
445
|
-
agent: agent,
|
|
446
|
-
activity: activity,
|
|
447
|
-
callback: function (err, sr) {
|
|
448
|
-
if (err !== null) {
|
|
449
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
450
|
-
dfd.reject(error);
|
|
451
|
-
} else {
|
|
452
|
-
dfd.resolve(sr);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
return dfd.promise;
|
|
458
|
-
}*/
|
|
459
|
-
|