comprodls-sdk 2.90.3-development → 2.91.0-thor

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 (42) hide show
  1. package/README.md +1 -137
  2. package/dist/comprodls-sdk.js +2917 -6291
  3. package/dist/comprodls-sdk.min.js +1 -1
  4. package/lib/comprodls.js +39 -57
  5. package/lib/config/index.js +172 -198
  6. package/lib/helpers/index.js +3 -2
  7. package/lib/helpers/lib/api/converter.js +1 -2
  8. package/lib/helpers/lib/api/index.js +19 -94
  9. package/lib/helpers/lib/errors.js +75 -80
  10. package/lib/helpers/lib/requestLayer.js +154 -0
  11. package/lib/helpers/lib/validator.js +65 -52
  12. package/lib/open_access/index.js +48 -53
  13. package/lib/services/analytics/index.js +286 -1014
  14. package/lib/services/attempts/index.js +38 -88
  15. package/lib/services/auth/index.js +324 -806
  16. package/lib/services/authextn/index.js +85 -247
  17. package/lib/services/datasyncmanager/index.js +10 -45
  18. package/lib/services/drive/index.js +20 -83
  19. package/lib/services/integrations/index.js +51 -126
  20. package/lib/services/invitations/index.js +20 -61
  21. package/lib/services/product/index.js +82 -85
  22. package/lib/services/pub/index.js +167 -235
  23. package/lib/services/pushX/index.js +195 -142
  24. package/lib/services/pushX/pubnubClientWrapper.js +399 -172
  25. package/lib/services/rules/index.js +14 -67
  26. package/lib/services/spaces/index.js +106 -289
  27. package/lib/services/spacesextn/index.js +44 -20
  28. package/lib/services/superuser/index.js +21 -36
  29. package/lib/services/taxonomy/index.js +27 -57
  30. package/lib/services/workflows/index.js +38 -97
  31. package/lib/services/xapi/index.js +7 -168
  32. package/lib/token/index.js +73 -67
  33. package/lib/token/validations.js +45 -48
  34. package/package.json +2 -3
  35. package/lib/helpers/lib/api/validations.js +0 -73
  36. package/lib/helpers/lib/utils.js +0 -24
  37. package/lib/services/activity/activity.js +0 -209
  38. package/lib/services/activity/attempt.js +0 -431
  39. package/lib/services/activity/index.js +0 -28
  40. package/lib/services/auth/classProduct.js +0 -37
  41. package/lib/services/collab/index.js +0 -468
  42. package/test.js +0 -38
@@ -23,31 +23,32 @@
23
23
  * Functions for calling PUSHX.
24
24
  ************************************************************/
25
25
 
26
-
27
26
  var q = require('q');
28
27
  var request = require('superagent');
28
+ var Agent = require('agentkeepalive');
29
29
 
30
30
  var helpers = require('../../helpers');
31
31
  var pubnubClientWrapper = require('./pubnubClientWrapper');
32
32
  var DLSError = helpers.errors.DLSError;
33
33
 
34
- /*********************************
35
- * Setting Up Module Entry Point
36
- **********************************/
37
34
  module.exports = pushX;
38
35
 
39
- /*********************************
40
- * Public Function definitions
41
- **********************************/
36
+ var keepaliveAgent = new Agent({
37
+ timeout: 60000,
38
+ freeSocketTimeout: 30000
39
+ });
40
+
42
41
  function pushX() {
43
- var _pubnubClientWrapper = pubnubClientWrapper();
44
- return {
45
- "connect": _connect.bind(this, _pubnubClientWrapper),
46
- "cleanup": _cleanup.bind(this, _pubnubClientWrapper),
47
- "grantByUserOrgId": grantByUserOrgId.bind(this),
48
- "grantByAccountId": grantByAccountId.bind(this),
49
- "grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this)
50
- };
42
+ var _pubnubClientWrapper = pubnubClientWrapper();
43
+ return {
44
+ connect: _connect.bind(this, _pubnubClientWrapper),
45
+ cleanup: _cleanup.bind(this, _pubnubClientWrapper),
46
+ grantByUserOrgId: grantByUserOrgId.bind(this),
47
+ grantByAccountId: grantByAccountId.bind(this),
48
+ grantByAccountIdOnExtUserId: grantByAccountIdOnExtUserId.bind(this),
49
+ grantV2: grantV2.bind(this),
50
+ getPushedEvents: getPushedEvents.bind(this)
51
+ };
51
52
  }
52
53
 
53
54
  /*********************************
@@ -55,144 +56,196 @@ function pushX() {
55
56
  **********************************/
56
57
 
57
58
  function _connect(pubnubCW, options) {
58
- var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
59
- if (bpubnubV7 && !options.userid) {
60
- var err = {};
61
- err.message = err.description = 'Mandatory parameter userid not found in request options.';
62
- err = new DLSError(helpers.errors.ERROR_TYPES.PUSHX_ERROR, err);
63
- throw err;
64
- }
65
-
66
- // Adding SSL flag
67
- return pubnubCW.setup({
68
- 'userid': options.userid,
69
- 'pubnub': {
70
- 'publishKey': options.publishKey,
71
- 'subscribeKey': options.subscribeKey,
72
- 'authKey': options.authKey,
73
- 'ssl': true
74
- }
75
- });
59
+ var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
60
+ if (bpubnubV7 && !options.userid) {
61
+ var err = {};
62
+ err.message = err.description = 'Mandatory parameter userid not found in request options.';
63
+ err = new DLSError(helpers.errors.ERROR_TYPES.PUSHX_ERROR, err);
64
+ throw err;
65
+ }
66
+
67
+ // Adding SSL flag
68
+ return pubnubCW.setup({
69
+ 'userid': options.userid,
70
+ 'accountid': options.accountid,
71
+ 'token': options.token,
72
+ 'pubnub': {
73
+ 'publishKey': options.publishKey,
74
+ 'subscribeKey': options.subscribeKey,
75
+ 'ssl': true,
76
+ 'suppressLeaveEvents': true
77
+ },
78
+ 'pollingEndpoint': options.pollingEndpoint,
79
+ 'pollingIterations': options.pollingIterations || 10, // Default polling iterations is 10
80
+ 'pollingInterval': options.pollingInterval, // Default polling interval is exponential backoff
81
+ });
76
82
  }
77
83
 
84
+ /**
85
+ * Wiki Link for SDK params
86
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#cleanup
87
+ */
78
88
  function _cleanup(pubnubCW) { pubnubCW.cleanup(); }
79
89
 
80
- /*options = {
81
- authKey: <authKey>
82
- }*/
90
+ /**
91
+ * Wiki Link for SDK params
92
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-user--org-level-grants
93
+ */
83
94
  function grantByUserOrgId(options) {
84
- var self = this;
85
- var dfd = q.defer(); // Initializing promise
86
- // Validations
87
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
88
- if(err) { dfd.reject(err); }
89
- else {
90
- // Passed all validations, Construct API url
91
- var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantByUserOrgId;
92
- url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
93
- // Setup request with URL and Params
94
- var requestAPI = request.post(url)
95
- .set('Content-Type', 'application/json')
96
- .set('Accept', 'application/json');
97
-
98
- var body = {};
99
- if(options.authKey) { body.authKey = options.authKey; }
100
-
101
- requestAPI.send(body);
102
-
103
- //Setup token in Authorization header
104
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
105
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
106
-
107
- // Call Change Password Api
108
- requestAPI.end(function(err, response) {
109
- if(err) {
110
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
111
- dfd.reject(err);
112
- }
113
- else { dfd.resolve(response.body); }
114
- });
115
- }
116
- return dfd.promise;
95
+ var dfd = q.defer(); // Initializing promise
96
+ var allowedChannels = ['jobs', 'systemevents'];
97
+ var baseChannelName = "o-" + this.orgId + "\\$u-" + this.token.access_token + "\\$";
98
+ var patterns = [];
99
+ for(var i in allowedChannels) {
100
+ var channelName = baseChannelName + allowedChannels[i] + "\\..*";
101
+ patterns.push(channelName);
102
+ }
103
+ options.channels = {};
104
+ options.channels.patterns = patterns;
105
+ grantV2.call(this, options)
106
+ .then(function (res) {
107
+ dfd.resolve(res);
108
+ })
109
+ .catch(function(err) {
110
+ dfd.reject(err);
111
+ });
112
+ return dfd.promise;
117
113
  }
118
114
 
119
- /*options = {
120
- accountId: <accountid>,
121
- refId: <extRefId>,
122
- authKey: <authKey>
123
- }*/
115
+ /**
116
+ * Wiki Link for SDK params
117
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-account-level-grants
118
+ */
124
119
  function grantByAccountId(options) {
125
- var self = this, err ={};
126
- var dfd = q.defer(); // Initializing promise
127
-
128
- if(options.accountId && options.refId) {
129
- // Passed all validations, Construct API url
130
- var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantByAccountId;
131
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountId });
132
- // Setup request with URL and Params
133
- var requestAPI = request.post(url)
134
- .set('Content-Type', 'application/json')
135
- .set('Accept', 'application/json');
136
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
137
-
138
- var body = { refId: options.refId };
139
- if(options.authKey) { body.authKey = options.authKey; }
140
-
141
- requestAPI.send(body);
142
- requestAPI.end(function(err, response) {
143
- if(err) {
144
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
145
- dfd.reject(err);
146
- }
147
- else { dfd.resolve(response.body); }
148
- });
149
- }
150
- else {
151
- err.message = err.description = "Required parameter ['accountId', 'refId'] " +
152
- "not found in request options";
153
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
154
- dfd.reject(err);
155
- }
156
- return dfd.promise;
120
+ var err ={};
121
+ var dfd = q.defer(); // Initializing promise
122
+
123
+ if(options.accountId && options.refId) {
124
+ var channel = "a-" + options.accountId + "$refid." + options.refId;
125
+ var exactMatch = [channel];
126
+ options.channels = {};
127
+ options.channels.exactMatch = exactMatch;
128
+ grantV2.call(this, options)
129
+ .then(function (res) {
130
+ dfd.resolve(res);
131
+ })
132
+ .catch(function(err) {
133
+ dfd.reject(err);
134
+ });
135
+ }
136
+ else {
137
+ err.message = err.description = "Required parameter ['accountId', 'refId'] " +
138
+ "not found in request options";
139
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
140
+ dfd.reject(err);
141
+ }
142
+ return dfd.promise;
157
143
  }
158
144
 
159
- /*options = {
160
- accountId: <accountid>,
161
- extUserId: <extUserId>, //mandatory
162
- authKey: <authKey>
163
- }*/
145
+ /**
146
+ * Wiki Link for SDK params
147
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-account-level-grants-on-extuserid
148
+ */
164
149
  function grantByAccountIdOnExtUserId(options) {
165
- var self = this, err ={};
166
- var dfd = q.defer(); // Initializing promise
167
-
168
- if(options.accountId && options.extUserId) {
169
- // Passed all validations, Construct API url
170
- var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantByAccountId;
171
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountId });
172
- // Setup request with URL and Params
173
- var requestAPI = request.post(url)
174
- .set('Content-Type', 'application/json')
175
- .set('Accept', 'application/json');
176
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
177
-
178
- var body = { extUserId: options.extUserId };
179
- if(options.authKey) { body.authKey = options.authKey; }
180
-
181
- requestAPI.send(body);
182
- requestAPI.end(function(err, response) {
183
- if(err) {
184
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
185
- dfd.reject(err);
186
- }
187
- else { dfd.resolve(response.body); }
188
- });
189
- }
190
- else {
191
- err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
192
- "not found in request options";
193
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
194
- dfd.reject(err);
195
- }
150
+ var err ={};
151
+ var dfd = q.defer(); // Initializing promise
152
+
153
+ if(options.accountId && options.extUserId) {
154
+ var channel = "a-" + options.accountId + "$u-" + options.extUserId;
155
+ var exactMatch = [channel];
156
+ options.channels = {};
157
+ options.channels.exactMatch = exactMatch;
158
+ grantV2.call(this, options)
159
+ .then(function (res) {
160
+ dfd.resolve(res);
161
+ })
162
+ .catch(function(err) {
163
+ dfd.reject(err);
164
+ });
165
+ }
166
+ else {
167
+ err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
168
+ "not found in request options";
169
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
170
+ dfd.reject(err);
171
+ }
172
+ return dfd.promise;
173
+ }
174
+
175
+ /**
176
+ * This function provides grant token on given channels
177
+ * Wiki Link for SDK params
178
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-grant-token-for-the-access-manager-v3
179
+ */
180
+ function grantV2(options) {
181
+ var self = this, err = {};
182
+ var dfd = q.defer();
183
+ var body = { channels: {} };
184
+ if(!options.channels) {
185
+ err.message = err.description = "channels not given in input body.";
186
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
187
+ dfd.reject(err);
196
188
  return dfd.promise;
189
+ }
190
+ body.channels = options.channels;
191
+ // Passed all validations, Construct API url
192
+ var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantV2;
193
+ // Setup request with URL and Params
194
+ var requestAPI = request.post(url)
195
+ .set('Content-Type', 'application/json')
196
+ .set('Accept', 'application/json');
197
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
198
+
199
+ requestAPI.send(body);
200
+ requestAPI.end(function(err, response) {
201
+ if(err) {
202
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
203
+ dfd.reject(err);
204
+ }
205
+ else { dfd.resolve(response.body); }
206
+ });
207
+ return dfd.promise;
197
208
  }
198
209
 
210
+ /**
211
+ * Wiki Link for SDK params
212
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#getpushedeventsparams
213
+ */
214
+ function getPushedEvents(options) {
215
+ var self = this;
216
+ var dfd = q.defer(); // Initializing promise
217
+ var accountid = options.accountid,
218
+ channelname = options.channelname,
219
+ starttime = options.starttime,
220
+ endtime = options.endtime;
221
+
222
+ if (accountid && channelname && starttime && endtime) {
223
+ // Passed all validations, Construct API url
224
+ var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.getPushedEvents;
225
+ url = helpers.api.constructAPIUrl(url, { accountId: accountid });
226
+
227
+ // Setup request with URL and Params
228
+ var params = {channelname: channelname, starttime: starttime, endtime: endtime};
229
+ var requestAPI = request.get(url).query(params);
230
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
231
+
232
+ requestAPI
233
+ .agent(keepaliveAgent)
234
+ .end(function(error, response) {
235
+ if (error) {
236
+ error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
237
+ dfd.reject(error);
238
+ } else {
239
+ dfd.resolve(response.body);
240
+ }
241
+ });
242
+ }
243
+ else {
244
+ var err = {};
245
+ err.message = err.description = 'Mandatory parameters [accountId, channelname,' +
246
+ ' starttime, endtime] not found in request options';
247
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
248
+ dfd.reject(err);
249
+ }
250
+ return dfd.promise;
251
+ }