comprodls-sdk 2.11.7 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.eslintrc +28 -28
  2. package/.npmignore +5 -0
  3. package/README.md +371 -371
  4. package/dist/comprodls-sdk.js +11493 -11301
  5. package/dist/comprodls-sdk.min.js +18 -18
  6. package/grunt/publish.js +148 -148
  7. package/lib/comprodls.js +146 -146
  8. package/lib/config/index.js +337 -336
  9. package/lib/helpers/index.js +29 -29
  10. package/lib/helpers/lib/api/converter.js +119 -119
  11. package/lib/helpers/lib/api/index.js +120 -120
  12. package/lib/helpers/lib/api/validations.js +72 -72
  13. package/lib/helpers/lib/errors.js +129 -129
  14. package/lib/helpers/lib/utils.js +23 -23
  15. package/lib/helpers/lib/validator.js +100 -100
  16. package/lib/open_access/index.js +121 -121
  17. package/lib/services/activity/activity.js +209 -209
  18. package/lib/services/activity/attempt.js +431 -431
  19. package/lib/services/activity/index.js +28 -28
  20. package/lib/services/analytics/index.js +1555 -1555
  21. package/lib/services/attempts/index.js +342 -342
  22. package/lib/services/auth/classProduct.js +37 -37
  23. package/lib/services/auth/index.js +2541 -2535
  24. package/lib/services/collab/index.js +468 -468
  25. package/lib/services/drive/index.js +144 -144
  26. package/lib/services/integrations/index.js +279 -116
  27. package/lib/services/invitations/index.js +313 -313
  28. package/lib/services/lrs/index.js +459 -459
  29. package/lib/services/product/index.js +267 -267
  30. package/lib/services/pub/index.js +407 -407
  31. package/lib/services/push/index.js +187 -187
  32. package/lib/services/push/pubnubClientWrapper.js +557 -557
  33. package/lib/services/push/sessionStorage.js +64 -64
  34. package/lib/services/pushX/index.js +190 -190
  35. package/lib/services/pushX/pubnubClientWrapper.js +211 -211
  36. package/lib/services/sisevents/index.js +113 -113
  37. package/lib/services/spaces/index.js +976 -929
  38. package/lib/services/superuser/index.js +175 -175
  39. package/lib/services/workflows/index.js +464 -464
  40. package/lib/services/xapi/index.js +232 -232
  41. package/lib/token/index.js +114 -114
  42. package/lib/token/validations.js +88 -88
  43. package/package-lock.json +5095 -0
  44. package/package.json +1 -1
  45. package/test.js +50 -50
  46. package/.vscode/launch.json +0 -23
  47. package/npm-debug.log.189866131 +0 -0
  48. package/npm-debug.log.712840116 +0 -26
package/README.md CHANGED
@@ -1,371 +1,371 @@
1
- # comproDLS SDK for Javascript
2
- The official comproDLS SDK for JavaScript, available for browsers and Node.js backends. It provides JavaScript objects and functions to access comproDLS APIs in your application.
3
-
4
- ## Key Concepts
5
-
6
- ### Javascript Promises
7
- Most of the functions in comproDLS SDK are asynchronous and returns a Javascript promise. We use [Q library] (https://github.com/kriskowal/q) for promises. If you are not familiar with promises, please go through [Q library documentation] (http://documentup.com/kriskowal/q/).
8
-
9
- ### What is a token?
10
- comproDLS uses a token based authentication mechanism i.e. it allows users to enter user credentials (organisationid, username and password) to obtain a security token. Once the token is obtained, this can be used to access protected resources/APIs instead of entering user credentials again. The method to obtain token is explained in [Usage](https://github.com/comprodls/comprodls-sdk-js#authwithcredentials) section.
11
-
12
- Please note, this token is valid for a limited time and needs to be refreshed after that time. However, you don't need to worry about refreshing token as SDK handles it automatically.
13
-
14
- ### Errors
15
- A standard error object is returned for all SDK functions:
16
- ```
17
- {
18
- "type": ... //API_ERROR or SDK_ERROR
19
- "message": ..
20
- ..
21
- ..
22
- }
23
- ```
24
- Possible error types are:
25
- - API_ERROR: In case there is some problem in the upstream comproDLS APIs themselves.
26
- - SDK_ERROR: In case of validation failure, invalid token or other problems within the SDK client.
27
-
28
- Please refer [Error Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/01_Getting-Started#errors) for detailed information.
29
-
30
- ## Supported APIs
31
- The SDK supports following APIs:
32
- <table>
33
- <thead>
34
- <th>API Name</th>
35
- <th>API Documentation</th>
36
- <th>API Version</th>
37
- </thead>
38
- <tbody>
39
- <tr><td>Auth API</td><td>http://auth.comprodls.com</td><td>1.0.0</td></tr>
40
- <tr><td>Product API</td><td>http://product.comprodls.com</td><td>1.0.0</td></tr>
41
- <tr><td>Collab API</td><td>http://collab.comprodls.com</td><td>1.0.0</td></tr>
42
- <tr><td>Analytics API</td><td>http://analytics.comprodls.com</td><td>1.0.0</td></tr>
43
- <tr><td>Activity / Test API</td><td>http://activity.comprodls.com</td><td>1.0.0</td></tr>
44
- <tr><td>xAPI</td><td>http://xapi.comprodls.com</td><td>1.0.0</td></tr>
45
- <tr><td>Push Notifications</td><td>---</td><td>1.0.0</td></tr>
46
- <tr><td>Pub</td><td>http://pub.comprodls.com</td><td>1.0.0</td></tr>
47
- </tbody>
48
- </table>
49
-
50
- ## Installation
51
- ### In Browser
52
- To use the SDK in browser, download latest [comprodls-sdk.min.js](https://raw.githubusercontent.com/comprodls/comprodls-sdk-js/master/dist/comprodls-sdk.min.js) and add the following script tag in your HTML page:
53
- ```javascript
54
- <script src="{SDK Folder location}/comprodls-sdk.min.js"></script>
55
- ```
56
- ### Using Bower
57
- You can also use [Bower](http://bower.io/) to install the SDK by typing the following into a terminal window:
58
- ```
59
- bower install comprodls-sdk
60
- ```
61
- ### In Node.js
62
- The preferred way to install the SDK for Node.js is to use the [npm](https://www.npmjs.com/) package manager for Node.js. Simply type the following into a terminal window:
63
- ```
64
- npm install comprodls-sdk
65
- ```
66
-
67
- ## Usage
68
- ### Loading the SDK
69
- #### In Browser
70
- Once comprodls-sdk.js is loaded, "comproDLS" package is available in window object itself.
71
- ```javascript
72
- var comproDLS = ComproDLS.init();
73
- ```
74
-
75
- However, if you are using AMD modules in your application, following is preferred way to get comproDLS package:
76
- ```javascript
77
- define(["comprodls-sdk"], function(ComproDLS) {
78
- var comproDLS = ComproDLS.init();
79
- });
80
- ```
81
-
82
- #### In Node.js
83
- After you've installed the SDK, you can require the comproDLS package in your application using require():
84
- ```javascript
85
- var comproDLS = require('comprodls-sdk').init();
86
- ```
87
- ### Authentication & Tokens
88
- Authentication (acquiring a valid token) is the first thing you need to do before using any function of comproDLS SDK. Following are the ways to authenticate:
89
-
90
- #### authWithCredentials
91
- You need valid comproDLS user credentials (organisationid, username and password) to use this method. Following is sample code to authenticate using credentials:
92
- ```javascript
93
- comproDLS.authWithCredentials("myorg", {username:"myusername", password:"mypassword"}, {}).then(
94
- function success(response) {
95
- //You may persist token object in session/localstorage etc. for later usage.
96
- var token = response["token"];
97
- console.log(token.expires_in);
98
-
99
- //user object contains user information
100
- var user = response["user"];
101
- console.log(user.name);
102
- console.log(user.roles);
103
-
104
- //org object contains organisation information
105
- var org = response["user"]["org"];
106
- console.log(org["type"]);
107
- },
108
- function error(err) {
109
- var type = err["type"];
110
- if (type == "API_ERROR") {
111
- if (err["httpcode"] == 401) {
112
- //Invalid Credentials
113
- console.log(err.message);
114
- }
115
- } else if (type == "SDK_ERROR") {
116
- console.log(err.message);
117
- }
118
- }
119
- );
120
- ```
121
- After successfully calling this function, the comproDLS SDK object will have a valid authentication token which will be used across all subsequent calls. All other SDK functions do not require the token or credentials (to be supplied as parameters). Furthermore, in case the token expires, SDK will automatically refresh it using the original credentials.
122
-
123
- See [authWithCredentials Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/02_Authentication-and-Tokens#authwithcredentials) for detailed information on method parameters, success and error response JSONs.
124
-
125
- #### authWithToken
126
-
127
- If you already have a persisted / saved comproDLS token (obtained via authWithCredentials method), you can use this method for a simple pass-through authentication (avoid generating a fresh token). Following is sample code:
128
- ```javascript
129
- /*
130
- * saved_token is token object obtained previously via authWithCredentials method
131
- */
132
- comproDLS.authWithToken('myorg', saved_token , {}).then(
133
- function success(response) {
134
- var token = response["token"];
135
- },
136
- function error(errorObject) {
137
- //Do error handling here
138
- }
139
- );
140
- ```
141
- After successfully calling this function, the comproDLS SDK object will have a valid authentication token which will be used across all subsequent calls. All other SDK functions do not require the token or credentials (to be supplied as parameters).
142
-
143
- This function returns token object in success response as shown above. However, if you need user and organisation information, please also pass ```getuserdetails:true``` option as shown below:
144
- ```javascript
145
- comproDLS.authWithToken('myorg', saved_token , {getuserdetails:true}).then(
146
- function success(response) {
147
- //You may persist token object in session/localstorage etc. for later usage.
148
- var token = response["token"];
149
- console.log(token.expires_in);
150
-
151
- //user object contains user information
152
- var user = response["user"];
153
- console.log(user.name);
154
- console.log(user.roles);
155
-
156
- //org object contains organisation information
157
- var org = response["user"]["org"];
158
- console.log(org["type"]);
159
- },
160
- function error(err) {
161
- var type = err["type"];
162
- if (type == "API_ERROR") {
163
- if (err["httpcode"] == 401) {
164
- //Invalid Credentials
165
- console.log(err.message);
166
- }
167
- } else if (type == "SDK_ERROR") {
168
- console.log(err.message);
169
- }
170
- }
171
- );
172
- ```
173
- See [authWithToken Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/02_Authentication-and-Tokens#authwithtoken) for detailed information on method parameters, success and error response JSONs.
174
-
175
-
176
- ### refreshToken
177
- The comproDLS token gets expired after a certain time. Normally SDK will take care of automatically refreshing the token for you. Alternately (rare cases), if you want to manage token renewal yourself, you will need to handle the appropriate EXPIRY events and call the **refreshToken** SDK function on your own. See [refreshToken Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/02_Authentication-and-Tokens#refreshtoken) for detailed information on method parameters, success and error response JSONs.
178
-
179
- ### Calling APIs using SDK Adaptors
180
-
181
- #### AUTH
182
- comproDLS AUTH API provides functions to deal with users, roles, permissions, groups, enrollments and classrooms.
183
- **Note** You should have authenticated with comproDLS (authWithToken or authWithCredentials) before using these functions.
184
-
185
- Following is an example of using AUTH API SDK adaptor to get profile information for the user. In this function, the SDK adaptor abstracts the knowledge of underlying REST URLs & Parameters, and offers a simpler interface. For a list of all SDK AUTH functions, see [AUTH Adaptor Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/04_AUTH-Adaptor).
186
- ```javascript
187
- var auth = comproDLS.Auth();
188
- auth.getUserProfile().then(
189
- function success(response) {
190
- //You may persist token object in session/localstorage etc. for later usage.
191
- var token = response["token"];
192
- console.log(token.expires_in);
193
-
194
- //user object contains user information
195
- var user = response["user"];
196
- console.log(user.name);
197
- console.log(user.roles);
198
-
199
- //org object contains organisation information
200
- var org = response["user"]["org"];
201
- console.log(org["type"]);
202
- },
203
- function error(err) {
204
- var type = err["type"];
205
- if (type == "API_ERROR") {
206
- if (err["httpcode"] == 401) {
207
- //Invalid Credentials
208
- console.log(err.message);
209
- }
210
- } else if (type == "SDK_ERROR") {
211
- console.log(err.message);
212
- }
213
- }
214
- );
215
- ```
216
- #### ACTIVITY
217
- comproDLS Activity API provides functions to track assignment/test/activities and related data for scores, attempts, etc.
218
- **Note** You should have authenticated with comproDLS (authWithToken or authWithCredentials) before using these functions.
219
-
220
- Following is an example of using ACTIVITY API SDK adaptor to get information of the activity. In this function, the SDK adaptor abstracts the knowledge of underlying REST URLs & Parameters, and offers a simpler interface. For a list of all SDK ACTIVITY functions, see [ACTIVITY Adaptor Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/09_ACTIVITY-Adaptor).
221
-
222
- ```javascript
223
- var activity = comproDLS.Activity(productId, activityId, classId);
224
-
225
- /* Get all the attempts of an activity for a user */
226
- activity.getDetails().then(
227
- function success(response) {
228
-
229
- var activity = response.activity;
230
- /*--Activity {
231
- activityid (string),
232
- timestaken (integer),
233
- timespent (integer),
234
- timeallowed (integer),
235
- savedstate (string),
236
- attempts (Array[Attempt], optional)
237
- }-- */
238
- },
239
- function error(err) {
240
- /* --- Error --- */
241
- }
242
- );
243
-
244
- /* Start the attempt and store the attempt id */
245
- activity.newAttempt(startParameters).then(
246
- function success(response) {
247
- var attempt = response["attempt"];
248
-
249
- },
250
- function error(err) {
251
- /* --- Error --- */
252
- }
253
- );
254
-
255
- /* Load In-process Attempt */
256
- var attempt = activity.getAttempt(attemptId).then(
257
- function success(response) {
258
- var attempt = response["attempt"];
259
-
260
- },
261
- function error(err) {
262
- /* --- Error --- */
263
- }
264
- );
265
-
266
- // Save attempt state
267
- attempt.saveState(savedstate).then(
268
- function success(response) {
269
- var status = response.status;
270
- },
271
- function error(err) {
272
- /* --- Error --- */
273
- }
274
- );
275
-
276
- // Retrieve attempt state
277
- attempt.getState().then(
278
- function success(response) {
279
- var state = response.state;
280
- },
281
- function error(err) {
282
- /* --- Error --- */
283
- }
284
- );
285
-
286
- // Submit
287
-
288
- activity.submit(userresponse).then(
289
- function success(response) {
290
- var status = response.status;
291
- },
292
- function error(err) {
293
- /* --- Error --- */
294
- }
295
- );
296
-
297
-
298
- <!--// Get scores
299
- activity.getAttemptScore().then(
300
- function success(response) {
301
-
302
- //get /{orgid}/{productid}/activity/{activityid}
303
- //loop and return score for attempt.id
304
- console.log("Success " + attempt.id);
305
- },
306
- function error(err) {
307
- /* --- Error --- */
308
- }
309
- );-->
310
-
311
-
312
- )
313
-
314
- ```
315
-
316
- #### PUSH
317
- comproDLS PUSH API provides functions to manage user presence (online status) and various notification events, such as collaboration, activity timeouts etc.
318
- **Note** PUSH API is designed to be used directly in the browser (websockets). Therefore, if you have already authenticated (server-side) you do not need to re-authenticate, and can simply provide *orgid* and *userid* (optional paramters) to the *connect* function as shown in the example below.
319
-
320
- Following is an example of using PUSH API SDK adaptor to get notifications on status of online users. For a list of all PUSH functions & notification events, see [PUSH Adaptor Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/10_PUSH-Adapter).
321
-
322
- ```javascript
323
- var push = comproDLS.Push();
324
-
325
- push.connect(orgid, userid).then(
326
- function callback(notifications) {
327
-
328
- notifications.on("push_connect", function (eventContext) {
329
- console.log("Successfully established a connection with the PUSH services");
330
-
331
- /* This automatically makes the current authenticated user online,
332
- * sending appropriate events (within the organization).
333
- */
334
- });
335
-
336
- notifications.on("push_error", function (eventContext) {
337
- if(eventContext.error.message == "connect_error") {
338
- console.log("Connect error, " + eventContext.error.description);
339
- } else (eventContext.error.message == "connect_timeout") {
340
- console.log("Timeout, " + eventContext.error.description);
341
- } else {
342
- console.log("Unknown error, " + eventContext.error.description);
343
- }
344
-
345
- /*
346
- * If Timeout, try connecting again..
347
- */
348
- });
349
-
350
- notifications.on("presence", function (eventContext) {
351
- console.log("List of all online users=" + eventContext.result);
352
- });
353
-
354
- notifications.on("presenceupdate", function (eventContext) {
355
- console.log("An online user may have gone offline, or changed his/her status");
356
- });
357
-
358
- },
359
- function error(err) {
360
- /*
361
- * An error occurred while establishing a connection with the PUSH services
362
- */
363
- var type = err["type"];
364
- if (type == "API_ERROR") {
365
- console.log(err.message);
366
- } else if (type == "SDK_ERROR") {
367
- console.log(err.message);
368
- }
369
- }
370
- );
371
-
1
+ # comproDLS SDK for Javascript
2
+ The official comproDLS SDK for JavaScript, available for browsers and Node.js backends. It provides JavaScript objects and functions to access comproDLS APIs in your application.
3
+
4
+ ## Key Concepts
5
+
6
+ ### Javascript Promises
7
+ Most of the functions in comproDLS SDK are asynchronous and returns a Javascript promise. We use [Q library] (https://github.com/kriskowal/q) for promises. If you are not familiar with promises, please go through [Q library documentation] (http://documentup.com/kriskowal/q/).
8
+
9
+ ### What is a token?
10
+ comproDLS uses a token based authentication mechanism i.e. it allows users to enter user credentials (organisationid, username and password) to obtain a security token. Once the token is obtained, this can be used to access protected resources/APIs instead of entering user credentials again. The method to obtain token is explained in [Usage](https://github.com/comprodls/comprodls-sdk-js#authwithcredentials) section.
11
+
12
+ Please note, this token is valid for a limited time and needs to be refreshed after that time. However, you don't need to worry about refreshing token as SDK handles it automatically.
13
+
14
+ ### Errors
15
+ A standard error object is returned for all SDK functions:
16
+ ```
17
+ {
18
+ "type": ... //API_ERROR or SDK_ERROR
19
+ "message": ..
20
+ ..
21
+ ..
22
+ }
23
+ ```
24
+ Possible error types are:
25
+ - API_ERROR: In case there is some problem in the upstream comproDLS APIs themselves.
26
+ - SDK_ERROR: In case of validation failure, invalid token or other problems within the SDK client.
27
+
28
+ Please refer [Error Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/01_Getting-Started#errors) for detailed information.
29
+
30
+ ## Supported APIs
31
+ The SDK supports following APIs:
32
+ <table>
33
+ <thead>
34
+ <th>API Name</th>
35
+ <th>API Documentation</th>
36
+ <th>API Version</th>
37
+ </thead>
38
+ <tbody>
39
+ <tr><td>Auth API</td><td>http://auth.comprodls.com</td><td>1.0.0</td></tr>
40
+ <tr><td>Product API</td><td>http://product.comprodls.com</td><td>1.0.0</td></tr>
41
+ <tr><td>Collab API</td><td>http://collab.comprodls.com</td><td>1.0.0</td></tr>
42
+ <tr><td>Analytics API</td><td>http://analytics.comprodls.com</td><td>1.0.0</td></tr>
43
+ <tr><td>Activity / Test API</td><td>http://activity.comprodls.com</td><td>1.0.0</td></tr>
44
+ <tr><td>xAPI</td><td>http://xapi.comprodls.com</td><td>1.0.0</td></tr>
45
+ <tr><td>Push Notifications</td><td>---</td><td>1.0.0</td></tr>
46
+ <tr><td>Pub</td><td>http://pub.comprodls.com</td><td>1.0.0</td></tr>
47
+ </tbody>
48
+ </table>
49
+
50
+ ## Installation
51
+ ### In Browser
52
+ To use the SDK in browser, download latest [comprodls-sdk.min.js](https://raw.githubusercontent.com/comprodls/comprodls-sdk-js/master/dist/comprodls-sdk.min.js) and add the following script tag in your HTML page:
53
+ ```javascript
54
+ <script src="{SDK Folder location}/comprodls-sdk.min.js"></script>
55
+ ```
56
+ ### Using Bower
57
+ You can also use [Bower](http://bower.io/) to install the SDK by typing the following into a terminal window:
58
+ ```
59
+ bower install comprodls-sdk
60
+ ```
61
+ ### In Node.js
62
+ The preferred way to install the SDK for Node.js is to use the [npm](https://www.npmjs.com/) package manager for Node.js. Simply type the following into a terminal window:
63
+ ```
64
+ npm install comprodls-sdk
65
+ ```
66
+
67
+ ## Usage
68
+ ### Loading the SDK
69
+ #### In Browser
70
+ Once comprodls-sdk.js is loaded, "comproDLS" package is available in window object itself.
71
+ ```javascript
72
+ var comproDLS = ComproDLS.init();
73
+ ```
74
+
75
+ However, if you are using AMD modules in your application, following is preferred way to get comproDLS package:
76
+ ```javascript
77
+ define(["comprodls-sdk"], function(ComproDLS) {
78
+ var comproDLS = ComproDLS.init();
79
+ });
80
+ ```
81
+
82
+ #### In Node.js
83
+ After you've installed the SDK, you can require the comproDLS package in your application using require():
84
+ ```javascript
85
+ var comproDLS = require('comprodls-sdk').init();
86
+ ```
87
+ ### Authentication & Tokens
88
+ Authentication (acquiring a valid token) is the first thing you need to do before using any function of comproDLS SDK. Following are the ways to authenticate:
89
+
90
+ #### authWithCredentials
91
+ You need valid comproDLS user credentials (organisationid, username and password) to use this method. Following is sample code to authenticate using credentials:
92
+ ```javascript
93
+ comproDLS.authWithCredentials("myorg", {username:"myusername", password:"mypassword"}, {}).then(
94
+ function success(response) {
95
+ //You may persist token object in session/localstorage etc. for later usage.
96
+ var token = response["token"];
97
+ console.log(token.expires_in);
98
+
99
+ //user object contains user information
100
+ var user = response["user"];
101
+ console.log(user.name);
102
+ console.log(user.roles);
103
+
104
+ //org object contains organisation information
105
+ var org = response["user"]["org"];
106
+ console.log(org["type"]);
107
+ },
108
+ function error(err) {
109
+ var type = err["type"];
110
+ if (type == "API_ERROR") {
111
+ if (err["httpcode"] == 401) {
112
+ //Invalid Credentials
113
+ console.log(err.message);
114
+ }
115
+ } else if (type == "SDK_ERROR") {
116
+ console.log(err.message);
117
+ }
118
+ }
119
+ );
120
+ ```
121
+ After successfully calling this function, the comproDLS SDK object will have a valid authentication token which will be used across all subsequent calls. All other SDK functions do not require the token or credentials (to be supplied as parameters). Furthermore, in case the token expires, SDK will automatically refresh it using the original credentials.
122
+
123
+ See [authWithCredentials Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/02_Authentication-and-Tokens#authwithcredentials) for detailed information on method parameters, success and error response JSONs.
124
+
125
+ #### authWithToken
126
+
127
+ If you already have a persisted / saved comproDLS token (obtained via authWithCredentials method), you can use this method for a simple pass-through authentication (avoid generating a fresh token). Following is sample code:
128
+ ```javascript
129
+ /*
130
+ * saved_token is token object obtained previously via authWithCredentials method
131
+ */
132
+ comproDLS.authWithToken('myorg', saved_token , {}).then(
133
+ function success(response) {
134
+ var token = response["token"];
135
+ },
136
+ function error(errorObject) {
137
+ //Do error handling here
138
+ }
139
+ );
140
+ ```
141
+ After successfully calling this function, the comproDLS SDK object will have a valid authentication token which will be used across all subsequent calls. All other SDK functions do not require the token or credentials (to be supplied as parameters).
142
+
143
+ This function returns token object in success response as shown above. However, if you need user and organisation information, please also pass ```getuserdetails:true``` option as shown below:
144
+ ```javascript
145
+ comproDLS.authWithToken('myorg', saved_token , {getuserdetails:true}).then(
146
+ function success(response) {
147
+ //You may persist token object in session/localstorage etc. for later usage.
148
+ var token = response["token"];
149
+ console.log(token.expires_in);
150
+
151
+ //user object contains user information
152
+ var user = response["user"];
153
+ console.log(user.name);
154
+ console.log(user.roles);
155
+
156
+ //org object contains organisation information
157
+ var org = response["user"]["org"];
158
+ console.log(org["type"]);
159
+ },
160
+ function error(err) {
161
+ var type = err["type"];
162
+ if (type == "API_ERROR") {
163
+ if (err["httpcode"] == 401) {
164
+ //Invalid Credentials
165
+ console.log(err.message);
166
+ }
167
+ } else if (type == "SDK_ERROR") {
168
+ console.log(err.message);
169
+ }
170
+ }
171
+ );
172
+ ```
173
+ See [authWithToken Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/02_Authentication-and-Tokens#authwithtoken) for detailed information on method parameters, success and error response JSONs.
174
+
175
+
176
+ ### refreshToken
177
+ The comproDLS token gets expired after a certain time. Normally SDK will take care of automatically refreshing the token for you. Alternately (rare cases), if you want to manage token renewal yourself, you will need to handle the appropriate EXPIRY events and call the **refreshToken** SDK function on your own. See [refreshToken Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/02_Authentication-and-Tokens#refreshtoken) for detailed information on method parameters, success and error response JSONs.
178
+
179
+ ### Calling APIs using SDK Adaptors
180
+
181
+ #### AUTH
182
+ comproDLS AUTH API provides functions to deal with users, roles, permissions, groups, enrollments and classrooms.
183
+ **Note** You should have authenticated with comproDLS (authWithToken or authWithCredentials) before using these functions.
184
+
185
+ Following is an example of using AUTH API SDK adaptor to get profile information for the user. In this function, the SDK adaptor abstracts the knowledge of underlying REST URLs & Parameters, and offers a simpler interface. For a list of all SDK AUTH functions, see [AUTH Adaptor Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/04_AUTH-Adaptor).
186
+ ```javascript
187
+ var auth = comproDLS.Auth();
188
+ auth.getUserProfile().then(
189
+ function success(response) {
190
+ //You may persist token object in session/localstorage etc. for later usage.
191
+ var token = response["token"];
192
+ console.log(token.expires_in);
193
+
194
+ //user object contains user information
195
+ var user = response["user"];
196
+ console.log(user.name);
197
+ console.log(user.roles);
198
+
199
+ //org object contains organisation information
200
+ var org = response["user"]["org"];
201
+ console.log(org["type"]);
202
+ },
203
+ function error(err) {
204
+ var type = err["type"];
205
+ if (type == "API_ERROR") {
206
+ if (err["httpcode"] == 401) {
207
+ //Invalid Credentials
208
+ console.log(err.message);
209
+ }
210
+ } else if (type == "SDK_ERROR") {
211
+ console.log(err.message);
212
+ }
213
+ }
214
+ );
215
+ ```
216
+ #### ACTIVITY
217
+ comproDLS Activity API provides functions to track assignment/test/activities and related data for scores, attempts, etc.
218
+ **Note** You should have authenticated with comproDLS (authWithToken or authWithCredentials) before using these functions.
219
+
220
+ Following is an example of using ACTIVITY API SDK adaptor to get information of the activity. In this function, the SDK adaptor abstracts the knowledge of underlying REST URLs & Parameters, and offers a simpler interface. For a list of all SDK ACTIVITY functions, see [ACTIVITY Adaptor Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/09_ACTIVITY-Adaptor).
221
+
222
+ ```javascript
223
+ var activity = comproDLS.Activity(productId, activityId, classId);
224
+
225
+ /* Get all the attempts of an activity for a user */
226
+ activity.getDetails().then(
227
+ function success(response) {
228
+
229
+ var activity = response.activity;
230
+ /*--Activity {
231
+ activityid (string),
232
+ timestaken (integer),
233
+ timespent (integer),
234
+ timeallowed (integer),
235
+ savedstate (string),
236
+ attempts (Array[Attempt], optional)
237
+ }-- */
238
+ },
239
+ function error(err) {
240
+ /* --- Error --- */
241
+ }
242
+ );
243
+
244
+ /* Start the attempt and store the attempt id */
245
+ activity.newAttempt(startParameters).then(
246
+ function success(response) {
247
+ var attempt = response["attempt"];
248
+
249
+ },
250
+ function error(err) {
251
+ /* --- Error --- */
252
+ }
253
+ );
254
+
255
+ /* Load In-process Attempt */
256
+ var attempt = activity.getAttempt(attemptId).then(
257
+ function success(response) {
258
+ var attempt = response["attempt"];
259
+
260
+ },
261
+ function error(err) {
262
+ /* --- Error --- */
263
+ }
264
+ );
265
+
266
+ // Save attempt state
267
+ attempt.saveState(savedstate).then(
268
+ function success(response) {
269
+ var status = response.status;
270
+ },
271
+ function error(err) {
272
+ /* --- Error --- */
273
+ }
274
+ );
275
+
276
+ // Retrieve attempt state
277
+ attempt.getState().then(
278
+ function success(response) {
279
+ var state = response.state;
280
+ },
281
+ function error(err) {
282
+ /* --- Error --- */
283
+ }
284
+ );
285
+
286
+ // Submit
287
+
288
+ activity.submit(userresponse).then(
289
+ function success(response) {
290
+ var status = response.status;
291
+ },
292
+ function error(err) {
293
+ /* --- Error --- */
294
+ }
295
+ );
296
+
297
+
298
+ <!--// Get scores
299
+ activity.getAttemptScore().then(
300
+ function success(response) {
301
+
302
+ //get /{orgid}/{productid}/activity/{activityid}
303
+ //loop and return score for attempt.id
304
+ console.log("Success " + attempt.id);
305
+ },
306
+ function error(err) {
307
+ /* --- Error --- */
308
+ }
309
+ );-->
310
+
311
+
312
+ )
313
+
314
+ ```
315
+
316
+ #### PUSH
317
+ comproDLS PUSH API provides functions to manage user presence (online status) and various notification events, such as collaboration, activity timeouts etc.
318
+ **Note** PUSH API is designed to be used directly in the browser (websockets). Therefore, if you have already authenticated (server-side) you do not need to re-authenticate, and can simply provide *orgid* and *userid* (optional paramters) to the *connect* function as shown in the example below.
319
+
320
+ Following is an example of using PUSH API SDK adaptor to get notifications on status of online users. For a list of all PUSH functions & notification events, see [PUSH Adaptor Documentation](https://github.com/comprodls/comprodls-sdk-js/wiki/10_PUSH-Adapter).
321
+
322
+ ```javascript
323
+ var push = comproDLS.Push();
324
+
325
+ push.connect(orgid, userid).then(
326
+ function callback(notifications) {
327
+
328
+ notifications.on("push_connect", function (eventContext) {
329
+ console.log("Successfully established a connection with the PUSH services");
330
+
331
+ /* This automatically makes the current authenticated user online,
332
+ * sending appropriate events (within the organization).
333
+ */
334
+ });
335
+
336
+ notifications.on("push_error", function (eventContext) {
337
+ if(eventContext.error.message == "connect_error") {
338
+ console.log("Connect error, " + eventContext.error.description);
339
+ } else (eventContext.error.message == "connect_timeout") {
340
+ console.log("Timeout, " + eventContext.error.description);
341
+ } else {
342
+ console.log("Unknown error, " + eventContext.error.description);
343
+ }
344
+
345
+ /*
346
+ * If Timeout, try connecting again..
347
+ */
348
+ });
349
+
350
+ notifications.on("presence", function (eventContext) {
351
+ console.log("List of all online users=" + eventContext.result);
352
+ });
353
+
354
+ notifications.on("presenceupdate", function (eventContext) {
355
+ console.log("An online user may have gone offline, or changed his/her status");
356
+ });
357
+
358
+ },
359
+ function error(err) {
360
+ /*
361
+ * An error occurred while establishing a connection with the PUSH services
362
+ */
363
+ var type = err["type"];
364
+ if (type == "API_ERROR") {
365
+ console.log(err.message);
366
+ } else if (type == "SDK_ERROR") {
367
+ console.log(err.message);
368
+ }
369
+ }
370
+ );
371
+