comprodls-sdk 2.81.0 → 2.82.0-alpha

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/lib/comprodls.js CHANGED
@@ -46,6 +46,7 @@ var drive = require('./services/drive');
46
46
  var taxonomy = require('./services/taxonomy');
47
47
  var rules = require('./services/rules');
48
48
  var datasyncmanager = require('./services/datasyncmanager');
49
+ var helloWorld = require('./services/helloworld');
49
50
 
50
51
 
51
52
  /*********************************
@@ -145,6 +146,7 @@ comproDLS.prototype.Invitations = invitations;
145
146
  comproDLS.prototype.Workflows = workflows;
146
147
  comproDLS.prototype.Integrations = integrations;
147
148
  comproDLS.prototype.Drive = drive;
149
+ comproDLS.prototype.HelloWorld = helloWorld;
148
150
  comproDLS.prototype.Taxonomy = taxonomy;
149
151
  comproDLS.prototype.Rules = rules;
150
152
  comproDLS.prototype.Datasyncmanager = datasyncmanager;
@@ -53,7 +53,8 @@ exports.REALM_HOSTS = {
53
53
  PRODUCT: 'http://dls-asgard-thor-1453383019.us-west-2.elb.amazonaws.com/lb-product',
54
54
  ANALYTICS: 'http://dls-asgard-thor-1453383019.us-west-2.elb.amazonaws.com/lb-analytics',
55
55
  INTEGRATION: 'http://dls-asgard-thor-1453383019.us-west-2.elb.amazonaws.com/lb-integrations',
56
- DRIVE: 'http://dls-asgard-thor-1453383019.us-west-2.elb.amazonaws.com/lb-drive'
56
+ DRIVE: 'http://dls-asgard-thor-1453383019.us-west-2.elb.amazonaws.com/lb-drive',
57
+ HELLOWORLD: 'http://dls-asgard-thor-1453383019.us-west-2.elb.amazonaws.com/lb-helloworld'
57
58
  }
58
59
  },
59
60
  CUP: {
@@ -370,6 +371,10 @@ exports.DRIVE_API_URLS = {
370
371
  documents: '/accounts/{accountid}/users/{userid}/documents/multi'
371
372
  };
372
373
 
374
+ exports.HELLO_WORLD_API_URLS = {
375
+ sayHello: '/org/{orgid}/hello?name=map-team'
376
+ };
377
+
373
378
  exports.TAXONOMY_API_URLS = {
374
379
  associateTagsWithEntity: '/org/{orgId}/taxonomy/associate-tags-with-entity',
375
380
  tags: '/org/{orgId}/context/{context}/taxonomy/{taxonomyId}/tags'
@@ -26,7 +26,9 @@
26
26
  var ERROR_TYPES = {
27
27
  "API_ERROR": "API_ERROR",
28
28
  "SDK_ERROR": "SDK_ERROR",
29
- "CHANNEL_SUBSCRIPTION": "CHANNEL_SUBSCRIPTION"
29
+ "CHANNEL_SUBSCRIPTION": "CHANNEL_SUBSCRIPTION",
30
+ "UNEXPECTED_ERROR": "UNEXPECTED_ERROR",
31
+ "POLLING_INITIATION": "POLLING_INITIATION"
30
32
  };
31
33
 
32
34
  var ERROR_CATEGORY = {
@@ -0,0 +1,81 @@
1
+ /*************************************************************************
2
+ *
3
+ * COMPRO CONFIDENTIAL
4
+ * __________________
5
+ *
6
+ * [2015] - [2020] Compro Technologies Private Limited
7
+ * All Rights Reserved.
8
+ *
9
+ * NOTICE: All information contained herein is, and remains
10
+ * the property of Compro Technologies Private Limited. The
11
+ * intellectual and technical concepts contained herein are
12
+ * proprietary to Compro Technologies Private Limited and may
13
+ * be covered by U.S. and Foreign Patents, patents in process,
14
+ * and are protected by trade secret or copyright law.
15
+ *
16
+ * Dissemination of this information or reproduction of this material
17
+ * is strictly forbidden unless prior written permission is obtained
18
+ * from Compro Technologies Pvt. Ltd..
19
+ ***************************************************************************/
20
+
21
+ /***********************************************************
22
+ * comproDLS SDK Hello World Service
23
+ * Function for calling Hello World API.
24
+ ************************************************************/
25
+
26
+ var q = require('q');
27
+ var request = require('superagent');
28
+ var Agent = require('agentkeepalive');
29
+
30
+ var helpers = require('../../helpers');
31
+ var DLSError = helpers.errors.DLSError;
32
+
33
+ module.exports = helloWorld;
34
+
35
+ var keepaliveAgent = new Agent({
36
+ timeout: 60000,
37
+ freeSocketTimeout: 30000
38
+ });
39
+
40
+ /*********************************
41
+ * Public Function definitions
42
+ **********************************/
43
+ function helloWorld() {
44
+ return {
45
+ sayHello: sayHello.bind(this)
46
+ };
47
+ }
48
+
49
+ /*
50
+ options = {
51
+ accountid : 'string', //mandatory
52
+ extuserid : 'string', //mandatory
53
+ }
54
+ */
55
+ function sayHello() {
56
+ var self = this;
57
+ var dfd = q.defer();
58
+
59
+ // Passed all validations, Construct API url
60
+ var url = self.config.DEFAULT_HOSTS.HELLOWORLD + self.config.HELLO_WORLD_API_URLS.sayHello;
61
+ var urlOptions = {
62
+ orgid: self.orgId,
63
+ };
64
+ url = helpers.api.constructAPIUrl(url, urlOptions);
65
+
66
+ // Setup request with URL
67
+ var requestAPI = request.get(url);
68
+
69
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
70
+
71
+ requestAPI.end(function (err, response) {
72
+ if (err) {
73
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
74
+ dfd.reject(err);
75
+ } else {
76
+ dfd.resolve(response.body);
77
+ }
78
+ });
79
+
80
+ return dfd.promise;
81
+ }
@@ -80,11 +80,8 @@ function _connect(pubnubCW, options) {
80
80
  'publishKey': options.publishKey,
81
81
  'subscribeKey': options.subscribeKey,
82
82
  'ssl': true
83
- },
84
- 'pollingEndpoint': options.pollingEndpoint,
85
- 'pollingIterations': options.pollingIterations || 10, // Default polling iterations is 10
86
- 'pollingInterval': options.pollingInterval, // Default polling interval is exponential backoff
87
- });
83
+ }
84
+ });
88
85
  }
89
86
 
90
87
  function _cleanup(pubnubCW) { pubnubCW.cleanup(); }
@@ -1,5 +1,4 @@
1
1
  var pubNub = require("pubnub");
2
- var request = require('superagent');
3
2
  var EventEmitter = require("events").EventEmitter;
4
3
  var helpers = require('../../helpers');
5
4
 
@@ -22,13 +21,6 @@ module.exports = function () {
22
21
  var _globalSubscription = [];
23
22
  var _globalSubscriptionStatus = {};
24
23
  var bStatusSubscribed = false;
25
- /** ID of the setTimeout - used for Polling events when PubNub fails */
26
- var _setTimeoutIDForPolling;
27
- /** Timestamp from when the events need to be fetched */
28
- var _startTimestampForPolling;
29
- /** Counter for polling */
30
- var _pollingCounter;
31
- var bPollingInitiated = false;
32
24
 
33
25
  /** ###### END OF MODULE GLOBALS */
34
26
 
@@ -44,9 +36,6 @@ module.exports = function () {
44
36
  //Returning the adaptor (Plain Javascript object)
45
37
  return {
46
38
  "on": function (channelObj, handler) {
47
- // If PubNub fails, we will fetch the events from this timestamp
48
- _startTimestampForPolling = Date.now();
49
-
50
39
  var pubNubChannel;
51
40
  var channelContext = [];
52
41
 
@@ -75,9 +64,6 @@ module.exports = function () {
75
64
  _eventEmitter.on(channelObj.channel, handler);
76
65
  bStatusSubscribed = true;
77
66
  }
78
-
79
- // Clean up the old events
80
- _checkOldBubbledEvents();
81
67
  },
82
68
  "getMySubscriptionStatus": __getMySubscriptionStatus
83
69
  };
@@ -91,10 +77,6 @@ module.exports = function () {
91
77
 
92
78
  var _translatePubnubStatus = function(status, options) {
93
79
  var channels = [], error, successObj;
94
-
95
- // If polling has been initiated, ignore all punnub status
96
- if (bPollingInitiated) return;
97
-
98
80
  switch (status.category) {
99
81
  case "PNConnectedCategory":
100
82
  if(status.operation === "PNSubscribeOperation") {
@@ -156,10 +138,11 @@ module.exports = function () {
156
138
  break;
157
139
  case "PNNetworkIssuesCategory":
158
140
  if(status.operation === 'PNSubscribeOperation') {
159
- if(!options.accountId || !_userOptions.pollingEndpoint) {
141
+ if(!options.accountId) {
160
142
  error = {
161
- message: "Polling initiation error: Missing mandatory parameters to initiate polling operation - [accountId, pollingEndpoint]",
162
- status: status.statusCode
143
+ message: "Missing mandatory parameters to initiate polling operation - accountId",
144
+ status: status.statusCode,
145
+ type: helpers.errors.ERROR_TYPES.POLLING_INITIATION,
163
146
  };
164
147
  error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
165
148
  _eventEmitter.emit('pushx_status', error);
@@ -173,9 +156,6 @@ module.exports = function () {
173
156
  * The wrapper supports multiple channels, but the APP currently uses a single channel only.
174
157
  * Polling will also limited to a single channel.
175
158
  */
176
- _pollingCounter = 0;
177
- _pollForEvents();
178
- bPollingInitiated = true;
179
159
  }
180
160
  }
181
161
  else {
@@ -188,8 +168,9 @@ module.exports = function () {
188
168
  default:
189
169
  // Emit error for other status-category received from pubnub
190
170
  error = {
191
- message: "PushX Error: unexpected error",
171
+ message: "PushX Error",
192
172
  status: status.statusCode,
173
+ type: helpers.errors.ERROR_TYPES.UNEXPECTED_ERROR,
193
174
  pushXError: status
194
175
  };
195
176
  error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
@@ -226,7 +207,6 @@ module.exports = function () {
226
207
  * @returns PROMISE.
227
208
  */
228
209
  var __setup = function (userOptions) {
229
-
230
210
  var pubnubConfig = userOptions.pubnub;
231
211
  pubnubConfig.uuid = userOptions.userid;
232
212
  var accountId = userOptions.accountid;
@@ -265,160 +245,8 @@ module.exports = function () {
265
245
  _globalSubscription = [];
266
246
  bStatusSubscribed = false;
267
247
  _globalSubscriptionStatus = {};
268
- bPollingInitiated = false;
269
248
  }
270
249
  _pubnubClient = undefined;
271
-
272
- // Clear the Polling
273
- if (_setTimeoutIDForPolling) {
274
- clearTimeout(_setTimeoutIDForPolling);
275
- // Setting the start time to now to clear the old events
276
- _startTimestampForPolling = Date.now();
277
- _checkOldBubbledEvents();
278
- _setTimeoutIDForPolling = undefined;
279
- _pollingCounter = undefined;
280
- _startTimestampForPolling = undefined;
281
- }
282
- };
283
-
284
- /**
285
- * Polling function
286
- */
287
- var _pollForEvents = function () {
288
- // Setup request params
289
- var params = {
290
- accountid: _userOptions.accountid,
291
- channelname: _globalSubscription[0],
292
- starttime: _startTimestampForPolling,
293
- endtime: Date.now()
294
- };
295
- var requestAPI = request.get(_userOptions.pollingEndpoint).query(params);
296
-
297
- requestAPI
298
- .end(function(error, response) {
299
-
300
- if (!error) {
301
- // Bubble the connected status
302
- if (_pollingCounter === 0) {
303
- // Set the status of the channel to subscribed
304
- if(_globalSubscriptionStatus[_globalSubscription[0]]) {
305
- _globalSubscriptionStatus[_globalSubscription[0]].status = 'subscribed';
306
- }
307
-
308
- var successObj = {
309
- category: 'PUSHX',
310
- type: 'CHANNEL_SUBSCRIPTION',
311
- status: 'SUCCESS',
312
- message: 'Success: Subscribed successfully.',
313
- httpcode: 200,
314
- data: {
315
- payload: {
316
- channels: _globalSubscription
317
- },
318
- message: 'Success: Subscribed successfully.'
319
- }
320
- };
321
- _eventEmitter.emit('pushx_status', successObj);
322
- }
323
-
324
- // Bubble the received events
325
- _bubblePolledEvents(response.body);
326
-
327
- // Increase the counter
328
- _pollingCounter++;
329
- }
330
-
331
- // Polling will be done only for specific number of times
332
- if (_pollingCounter > _userOptions.pollingIterations) {
333
- var error = {
334
- message: "Polling error: Polling limit exceeded",
335
- status: 429
336
- };
337
- error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
338
- _eventEmitter.emit('pushx_status', error);
339
- } else {
340
- var timeoutDelay;
341
-
342
- // If the polling interval is provided, use that
343
- if (_userOptions.pollingInterval) {
344
- timeoutDelay = _userOptions.pollingInterval * 60 * 1000;
345
- } else {
346
- // Else, use exponential backoff
347
- timeoutDelay = parseInt(Math.pow(1.3, _pollingCounter) * 10 * 1000, 10);
348
- }
349
-
350
- // Set timeout for next poll
351
- _setTimeoutIDForPolling = setTimeout(_pollForEvents, timeoutDelay);
352
- }
353
- });
354
- };
355
-
356
- /**
357
- * Bubble the polled events to the FE APP
358
- * @param {*} events - Events recieved from the polling endpoint
359
- */
360
- var _bubblePolledEvents = function (events) {
361
- // Load the old events from the session storage
362
- var oldEventData = _checkOldBubbledEvents();
363
-
364
- var oldEvents = oldEventData.events;
365
- var sessionStorageKey = oldEventData.key;
366
-
367
- for (var i = 0; i < events.entities.length; i++) {
368
- var event = events.entities[i];
369
- var eventId = event.pk + '_' + event.sk;
370
-
371
- // Check if the event is already emitted
372
- if (!oldEvents[eventId]) {
373
- oldEvents[eventId] = event.context.start_time;
374
-
375
- // Emit the event
376
- _eventEmitter.emit(_globalSubscription[0], event);
377
- }
378
- }
379
-
380
- // Save the bubbled events to session storage
381
- sessionStorage.setItem(sessionStorageKey, JSON.stringify(oldEvents));
382
- };
383
-
384
- /**
385
- * Check the old bubbled events and remove the events that are older than the start timestamp
386
- * @returns {object} - Object containing the key and the events
387
- */
388
- var _checkOldBubbledEvents = function () {
389
- var sessionStorageKey = 'comprodls.old_pushx_events.' + _userOptions.userid + '.' + _globalSubscription[0];
390
- var oldEvents = sessionStorage.getItem(sessionStorageKey);
391
-
392
- if (oldEvents) {
393
- try {
394
- oldEvents = JSON.parse(oldEvents);
395
- } catch (e) {
396
- oldEvents = {};
397
- }
398
-
399
- var oldEventIds = Object.keys(oldEvents);
400
-
401
- // Remove the events that are older than the start timestamp
402
- for (var i = 0; i < oldEventIds.length; i++) {
403
- var oldEventId = oldEventIds[i];
404
-
405
- if (oldEvents[oldEventId] < _startTimestampForPolling) {
406
- delete oldEvents[oldEventId];
407
- }
408
- }
409
-
410
- // If the number of events has changed, save the events
411
- if (oldEventIds.length !== Object.keys(oldEvents).length) {
412
- sessionStorage.setItem(sessionStorageKey, JSON.stringify(oldEvents));
413
- }
414
- } else {
415
- oldEvents = {};
416
- }
417
-
418
- return {
419
- key: sessionStorageKey,
420
- events: oldEvents
421
- };
422
250
  };
423
251
 
424
252
  return { // Return public methods for the wrapper
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "comprodls-sdk",
3
3
  "description": "comproDLS SDK for JavaScript",
4
- "version": "2.81.0",
4
+ "version": "2.82.0-alpha",
5
5
  "author": {
6
6
  "name": "Compro Technologies Private Limited",
7
7
  "url": "http://www.comprotechnologies.com/"