comprodls-sdk 2.123.2-security → 2.123.3-oidc-poc.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 (36) hide show
  1. package/.eslintrc +28 -28
  2. package/.github/workflows/npm-publish.yml +76 -0
  3. package/README.md +235 -235
  4. package/dist/comprodls-sdk.js +13543 -13543
  5. package/docs/npm-oidc-publishing-runbook.md +229 -0
  6. package/lib/comprodls.js +132 -132
  7. package/lib/config/index.js +356 -356
  8. package/lib/helpers/index.js +31 -31
  9. package/lib/helpers/lib/api/converter.js +129 -129
  10. package/lib/helpers/lib/api/index.js +46 -46
  11. package/lib/helpers/lib/errors.js +122 -122
  12. package/lib/helpers/lib/requestLayer.js +154 -154
  13. package/lib/helpers/lib/validator.js +192 -192
  14. package/lib/open_access/index.js +116 -116
  15. package/lib/services/analytics/index.js +1365 -1365
  16. package/lib/services/attempts/index.js +389 -389
  17. package/lib/services/auth/index.js +3708 -3708
  18. package/lib/services/authextn/index.js +1032 -1032
  19. package/lib/services/datasyncmanager/index.js +275 -275
  20. package/lib/services/drive/index.js +270 -270
  21. package/lib/services/integrations/index.js +525 -525
  22. package/lib/services/invitations/index.js +282 -282
  23. package/lib/services/product/index.js +343 -343
  24. package/lib/services/pub/index.js +530 -530
  25. package/lib/services/pushX/index.js +251 -251
  26. package/lib/services/pushX/pubnubClientWrapper.js +438 -438
  27. package/lib/services/rules/index.js +416 -416
  28. package/lib/services/spaces/index.js +999 -999
  29. package/lib/services/spacesextn/index.js +131 -131
  30. package/lib/services/superuser/index.js +160 -160
  31. package/lib/services/taxonomy/index.js +405 -405
  32. package/lib/services/workflows/index.js +406 -406
  33. package/lib/services/xapi/index.js +114 -114
  34. package/lib/token/index.js +120 -120
  35. package/lib/token/validations.js +85 -85
  36. package/package.json +5 -1
package/.eslintrc CHANGED
@@ -1,29 +1,29 @@
1
-
2
- {
3
- "env": {
4
- "node": true
5
- },
6
- "parserOptions": {
7
- "ecmaVersion": 6,
8
- "sourceType": "module",
9
-
10
- "ecmaFeatures": {
11
- "jsx": true
12
- }
13
- },
14
- "rules": {
15
- "block-scoped-var": 2,
16
- "curly": 2,
17
- "eol-last": 2,
18
- "eqeqeq": [2, "smart"],
19
- "new-cap": 1,
20
- "no-extend-native": 2,
21
- "no-mixed-spaces-and-tabs": 2,
22
- "no-trailing-spaces": 2,
23
- "no-undef": 2,
24
- "no-use-before-define": [2, "nofunc"],
25
- "no-unused-vars": 1,
26
- "quotes": [2, "single", "avoid-escape"],
27
- "semi": [2, "always"]
28
- }
1
+
2
+ {
3
+ "env": {
4
+ "node": true
5
+ },
6
+ "parserOptions": {
7
+ "ecmaVersion": 6,
8
+ "sourceType": "module",
9
+
10
+ "ecmaFeatures": {
11
+ "jsx": true
12
+ }
13
+ },
14
+ "rules": {
15
+ "block-scoped-var": 2,
16
+ "curly": 2,
17
+ "eol-last": 2,
18
+ "eqeqeq": [2, "smart"],
19
+ "new-cap": 1,
20
+ "no-extend-native": 2,
21
+ "no-mixed-spaces-and-tabs": 2,
22
+ "no-trailing-spaces": 2,
23
+ "no-undef": 2,
24
+ "no-use-before-define": [2, "nofunc"],
25
+ "no-unused-vars": 1,
26
+ "quotes": [2, "single", "avoid-escape"],
27
+ "semi": [2, "always"]
28
+ }
29
29
  }
@@ -0,0 +1,76 @@
1
+ name: Publish SDK to npm
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: "Version without 'v' (e.g. 2.127.0 or 2.127.0-qa.1)"
8
+ required: true
9
+ type: string
10
+ npm_tag:
11
+ description: "npm dist-tag ('latest' = production)"
12
+ required: false
13
+ default: latest
14
+ type: choice
15
+ options: [qa, thor, valky, test, latest]
16
+ # TEMP (POC only, remove before merging): workflow_dispatch needs the file on master,
17
+ # so on the POC branch a push that changes this file starts a publish instead.
18
+ push:
19
+ branches: [sdk-release-upgrade-poc]
20
+ paths: ['.github/workflows/npm-publish.yml']
21
+
22
+ permissions:
23
+ contents: write # push the release commit and git tag
24
+ id-token: write # required for npm OIDC
25
+
26
+ concurrency:
27
+ group: npm-publish
28
+ cancel-in-progress: false
29
+
30
+ jobs:
31
+ publish:
32
+ runs-on: ubuntu-latest # must be GitHub-hosted; self-hosted runners aren't supported
33
+ environment: ${{ inputs.npm_tag == 'latest' && 'npm-production' || 'npm-non-production' }}
34
+ env:
35
+ # TEMP (POC only): push runs have no inputs, so these fallbacks are used. Bump the version for each attempt.
36
+ VERSION: ${{ inputs.version || '2.123.3-oidc-poc.1' }}
37
+ NPM_TAG: ${{ inputs.npm_tag || 'test' }}
38
+ steps:
39
+ - name: Validate inputs
40
+ run: |
41
+ if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
42
+ echo "::error::Invalid semver: $VERSION"; exit 1; fi
43
+ if [[ "$NPM_TAG" == "latest" && "$VERSION" == *-* ]]; then
44
+ echo "::error::Prerelease versions cannot go to 'latest'"; exit 1; fi
45
+ if [[ "$NPM_TAG" == "latest" && "$GITHUB_REF_NAME" != "master" ]]; then
46
+ echo "::error::'latest' must be released from master"; exit 1; fi
47
+
48
+ - uses: actions/checkout@v6
49
+ with:
50
+ fetch-depth: 0
51
+
52
+ - uses: actions/setup-node@v6
53
+ with:
54
+ node-version: "22"
55
+ registry-url: "https://registry.npmjs.org"
56
+ package-manager-cache: false
57
+
58
+ - name: Upgrade npm (OIDC needs 11.5.1 or later)
59
+ run: npm install -g npm@latest && npm --version
60
+
61
+ - name: Install dependencies
62
+ run: npm install --no-package-lock --no-audit --no-fund # keeps the release commit free of a lockfile
63
+
64
+ - name: Configure git identity
65
+ run: |
66
+ git config user.name "github-actions[bot]"
67
+ git config user.email "41898828+github-actions[bot]@users.noreply.github.com"
68
+
69
+ - name: Build, commit, tag, push, publish
70
+ env:
71
+ GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72
+ NPM_CONFIG_PROVENANCE: "false" # private repo: provenance isn't supported
73
+ run: |
74
+ npx --yes grunt-cli@1.5.0 "release:$VERSION" \
75
+ --TAG="$NPM_TAG" \
76
+ --SDK_RELEASE_BRANCH="$GITHUB_REF_NAME"
package/README.md CHANGED
@@ -1,235 +1,235 @@
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>Analytics API</td><td>http://analytics.comprodls.com</td><td>1.0.0</td></tr>
42
- <tr><td>xAPI</td><td>http://xapi.comprodls.com</td><td>1.0.0</td></tr>
43
- <tr><td>Push Notifications</td><td>---</td><td>1.0.0</td></tr>
44
- <tr><td>Pub</td><td>http://pub.comprodls.com</td><td>1.0.0</td></tr>
45
- </tbody>
46
- </table>
47
-
48
- ## Installation
49
- ### In Browser
50
- 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:
51
- ```javascript
52
- <script src="{SDK Folder location}/comprodls-sdk.min.js"></script>
53
- ```
54
- ### Using Bower
55
- You can also use [Bower](http://bower.io/) to install the SDK by typing the following into a terminal window:
56
- ```
57
- bower install comprodls-sdk
58
- ```
59
- ### In Node.js
60
- 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:
61
- ```
62
- npm install comprodls-sdk
63
- ```
64
-
65
- ## Usage
66
- ### Loading the SDK
67
- #### In Browser
68
- Once comprodls-sdk.js is loaded, "comproDLS" package is available in window object itself.
69
- ```javascript
70
- var comproDLS = ComproDLS.init();
71
- ```
72
-
73
- However, if you are using AMD modules in your application, following is preferred way to get comproDLS package:
74
- ```javascript
75
- define(["comprodls-sdk"], function(ComproDLS) {
76
- var comproDLS = ComproDLS.init();
77
- });
78
- ```
79
-
80
- #### In Node.js
81
- After you've installed the SDK, you can require the comproDLS package in your application using require():
82
- ```javascript
83
- var comproDLS = require('comprodls-sdk').init();
84
- ```
85
- ### Authentication & Tokens
86
- 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:
87
-
88
- #### authWithToken
89
-
90
- If you already have a persisted / saved comproDLS token, you can use this method for a simple pass-through authentication (avoid generating a fresh token). Following is sample code:
91
- ```javascript
92
- /*
93
- * saved_token is token object obtained previously via authWithCredentials method
94
- */
95
- comproDLS.authWithToken('myorg', saved_token , {}).then(
96
- function success(response) {
97
- var token = response["token"];
98
- },
99
- function error(errorObject) {
100
- //Do error handling here
101
- }
102
- );
103
- ```
104
- 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).
105
-
106
- 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:
107
- ```javascript
108
- comproDLS.authWithToken('myorg', saved_token , {getuserdetails:true}).then(
109
- function success(response) {
110
- //You may persist token object in session/localstorage etc. for later usage.
111
- var token = response["token"];
112
- console.log(token.expires_in);
113
-
114
- //user object contains user information
115
- var user = response["user"];
116
- console.log(user.name);
117
- console.log(user.roles);
118
-
119
- //org object contains organisation information
120
- var org = response["user"]["org"];
121
- console.log(org["type"]);
122
- },
123
- function error(err) {
124
- var type = err["type"];
125
- if (type == "API_ERROR") {
126
- if (err["httpcode"] == 401) {
127
- //Invalid Credentials
128
- console.log(err.message);
129
- }
130
- } else if (type == "SDK_ERROR") {
131
- console.log(err.message);
132
- }
133
- }
134
- );
135
- ```
136
- 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.
137
-
138
-
139
- ### refreshToken
140
- 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.
141
-
142
- ### Calling APIs using SDK Adaptors
143
-
144
- #### AUTH
145
- comproDLS AUTH API provides functions to deal with users, roles, permissions, groups, enrollments and classrooms.
146
- **Note** You should have authenticated with comproDLS (authWithToken or authWithCredentials) before using these functions.
147
-
148
- 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).
149
- ```javascript
150
- var auth = comproDLS.Auth();
151
- auth.getUserProfile().then(
152
- function success(response) {
153
- //You may persist token object in session/localstorage etc. for later usage.
154
- var token = response["token"];
155
- console.log(token.expires_in);
156
-
157
- //user object contains user information
158
- var user = response["user"];
159
- console.log(user.name);
160
- console.log(user.roles);
161
-
162
- //org object contains organisation information
163
- var org = response["user"]["org"];
164
- console.log(org["type"]);
165
- },
166
- function error(err) {
167
- var type = err["type"];
168
- if (type == "API_ERROR") {
169
- if (err["httpcode"] == 401) {
170
- //Invalid Credentials
171
- console.log(err.message);
172
- }
173
- } else if (type == "SDK_ERROR") {
174
- console.log(err.message);
175
- }
176
- }
177
- );
178
- ```
179
-
180
- #### PUSH
181
- comproDLS PUSH API provides functions to manage user presence (online status) and various notification events, such as collaboration, activity timeouts etc.
182
- **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.
183
-
184
- 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).
185
-
186
- ```javascript
187
- var push = comproDLS.Push();
188
-
189
- push.connect(orgid, userid).then(
190
- function callback(notifications) {
191
-
192
- notifications.on("push_connect", function (eventContext) {
193
- console.log("Successfully established a connection with the PUSH services");
194
-
195
- /* This automatically makes the current authenticated user online,
196
- * sending appropriate events (within the organization).
197
- */
198
- });
199
-
200
- notifications.on("push_error", function (eventContext) {
201
- if(eventContext.error.message == "connect_error") {
202
- console.log("Connect error, " + eventContext.error.description);
203
- } else (eventContext.error.message == "connect_timeout") {
204
- console.log("Timeout, " + eventContext.error.description);
205
- } else {
206
- console.log("Unknown error, " + eventContext.error.description);
207
- }
208
-
209
- /*
210
- * If Timeout, try connecting again..
211
- */
212
- });
213
-
214
- notifications.on("presence", function (eventContext) {
215
- console.log("List of all online users=" + eventContext.result);
216
- });
217
-
218
- notifications.on("presenceupdate", function (eventContext) {
219
- console.log("An online user may have gone offline, or changed his/her status");
220
- });
221
-
222
- },
223
- function error(err) {
224
- /*
225
- * An error occurred while establishing a connection with the PUSH services
226
- */
227
- var type = err["type"];
228
- if (type == "API_ERROR") {
229
- console.log(err.message);
230
- } else if (type == "SDK_ERROR") {
231
- console.log(err.message);
232
- }
233
- }
234
- );
235
-
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>Analytics API</td><td>http://analytics.comprodls.com</td><td>1.0.0</td></tr>
42
+ <tr><td>xAPI</td><td>http://xapi.comprodls.com</td><td>1.0.0</td></tr>
43
+ <tr><td>Push Notifications</td><td>---</td><td>1.0.0</td></tr>
44
+ <tr><td>Pub</td><td>http://pub.comprodls.com</td><td>1.0.0</td></tr>
45
+ </tbody>
46
+ </table>
47
+
48
+ ## Installation
49
+ ### In Browser
50
+ 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:
51
+ ```javascript
52
+ <script src="{SDK Folder location}/comprodls-sdk.min.js"></script>
53
+ ```
54
+ ### Using Bower
55
+ You can also use [Bower](http://bower.io/) to install the SDK by typing the following into a terminal window:
56
+ ```
57
+ bower install comprodls-sdk
58
+ ```
59
+ ### In Node.js
60
+ 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:
61
+ ```
62
+ npm install comprodls-sdk
63
+ ```
64
+
65
+ ## Usage
66
+ ### Loading the SDK
67
+ #### In Browser
68
+ Once comprodls-sdk.js is loaded, "comproDLS" package is available in window object itself.
69
+ ```javascript
70
+ var comproDLS = ComproDLS.init();
71
+ ```
72
+
73
+ However, if you are using AMD modules in your application, following is preferred way to get comproDLS package:
74
+ ```javascript
75
+ define(["comprodls-sdk"], function(ComproDLS) {
76
+ var comproDLS = ComproDLS.init();
77
+ });
78
+ ```
79
+
80
+ #### In Node.js
81
+ After you've installed the SDK, you can require the comproDLS package in your application using require():
82
+ ```javascript
83
+ var comproDLS = require('comprodls-sdk').init();
84
+ ```
85
+ ### Authentication & Tokens
86
+ 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:
87
+
88
+ #### authWithToken
89
+
90
+ If you already have a persisted / saved comproDLS token, you can use this method for a simple pass-through authentication (avoid generating a fresh token). Following is sample code:
91
+ ```javascript
92
+ /*
93
+ * saved_token is token object obtained previously via authWithCredentials method
94
+ */
95
+ comproDLS.authWithToken('myorg', saved_token , {}).then(
96
+ function success(response) {
97
+ var token = response["token"];
98
+ },
99
+ function error(errorObject) {
100
+ //Do error handling here
101
+ }
102
+ );
103
+ ```
104
+ 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).
105
+
106
+ 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:
107
+ ```javascript
108
+ comproDLS.authWithToken('myorg', saved_token , {getuserdetails:true}).then(
109
+ function success(response) {
110
+ //You may persist token object in session/localstorage etc. for later usage.
111
+ var token = response["token"];
112
+ console.log(token.expires_in);
113
+
114
+ //user object contains user information
115
+ var user = response["user"];
116
+ console.log(user.name);
117
+ console.log(user.roles);
118
+
119
+ //org object contains organisation information
120
+ var org = response["user"]["org"];
121
+ console.log(org["type"]);
122
+ },
123
+ function error(err) {
124
+ var type = err["type"];
125
+ if (type == "API_ERROR") {
126
+ if (err["httpcode"] == 401) {
127
+ //Invalid Credentials
128
+ console.log(err.message);
129
+ }
130
+ } else if (type == "SDK_ERROR") {
131
+ console.log(err.message);
132
+ }
133
+ }
134
+ );
135
+ ```
136
+ 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.
137
+
138
+
139
+ ### refreshToken
140
+ 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.
141
+
142
+ ### Calling APIs using SDK Adaptors
143
+
144
+ #### AUTH
145
+ comproDLS AUTH API provides functions to deal with users, roles, permissions, groups, enrollments and classrooms.
146
+ **Note** You should have authenticated with comproDLS (authWithToken or authWithCredentials) before using these functions.
147
+
148
+ 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).
149
+ ```javascript
150
+ var auth = comproDLS.Auth();
151
+ auth.getUserProfile().then(
152
+ function success(response) {
153
+ //You may persist token object in session/localstorage etc. for later usage.
154
+ var token = response["token"];
155
+ console.log(token.expires_in);
156
+
157
+ //user object contains user information
158
+ var user = response["user"];
159
+ console.log(user.name);
160
+ console.log(user.roles);
161
+
162
+ //org object contains organisation information
163
+ var org = response["user"]["org"];
164
+ console.log(org["type"]);
165
+ },
166
+ function error(err) {
167
+ var type = err["type"];
168
+ if (type == "API_ERROR") {
169
+ if (err["httpcode"] == 401) {
170
+ //Invalid Credentials
171
+ console.log(err.message);
172
+ }
173
+ } else if (type == "SDK_ERROR") {
174
+ console.log(err.message);
175
+ }
176
+ }
177
+ );
178
+ ```
179
+
180
+ #### PUSH
181
+ comproDLS PUSH API provides functions to manage user presence (online status) and various notification events, such as collaboration, activity timeouts etc.
182
+ **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.
183
+
184
+ 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).
185
+
186
+ ```javascript
187
+ var push = comproDLS.Push();
188
+
189
+ push.connect(orgid, userid).then(
190
+ function callback(notifications) {
191
+
192
+ notifications.on("push_connect", function (eventContext) {
193
+ console.log("Successfully established a connection with the PUSH services");
194
+
195
+ /* This automatically makes the current authenticated user online,
196
+ * sending appropriate events (within the organization).
197
+ */
198
+ });
199
+
200
+ notifications.on("push_error", function (eventContext) {
201
+ if(eventContext.error.message == "connect_error") {
202
+ console.log("Connect error, " + eventContext.error.description);
203
+ } else (eventContext.error.message == "connect_timeout") {
204
+ console.log("Timeout, " + eventContext.error.description);
205
+ } else {
206
+ console.log("Unknown error, " + eventContext.error.description);
207
+ }
208
+
209
+ /*
210
+ * If Timeout, try connecting again..
211
+ */
212
+ });
213
+
214
+ notifications.on("presence", function (eventContext) {
215
+ console.log("List of all online users=" + eventContext.result);
216
+ });
217
+
218
+ notifications.on("presenceupdate", function (eventContext) {
219
+ console.log("An online user may have gone offline, or changed his/her status");
220
+ });
221
+
222
+ },
223
+ function error(err) {
224
+ /*
225
+ * An error occurred while establishing a connection with the PUSH services
226
+ */
227
+ var type = err["type"];
228
+ if (type == "API_ERROR") {
229
+ console.log(err.message);
230
+ } else if (type == "SDK_ERROR") {
231
+ console.log(err.message);
232
+ }
233
+ }
234
+ );
235
+