comprodls-sdk 2.86.0-alpha → 2.86.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.
@@ -923,7 +923,9 @@ function validateGenericAPICaller(apiName, method, url, params) {
923
923
  var ERROR_TYPES = {
924
924
  "API_ERROR": "API_ERROR",
925
925
  "SDK_ERROR": "SDK_ERROR",
926
- "CHANNEL_SUBSCRIPTION": "CHANNEL_SUBSCRIPTION"
926
+ "CHANNEL_SUBSCRIPTION": "CHANNEL_SUBSCRIPTION",
927
+ "UNEXPECTED_ERROR": "UNEXPECTED_ERROR",
928
+ "POLLING_INITIATION": "POLLING_INITIATION"
927
929
  };
928
930
 
929
931
  var ERROR_CATEGORY = {
@@ -12992,10 +12994,7 @@ function _connect(pubnubCW, options) {
12992
12994
  'subscribeKey': options.subscribeKey,
12993
12995
  'ssl': true,
12994
12996
  'suppressLeaveEvents': true
12995
- },
12996
- 'pollingEndpoint': options.pollingEndpoint,
12997
- 'pollingIterations': options.pollingIterations || 10, // Default polling iterations is 10
12998
- 'pollingInterval': options.pollingInterval, // Default polling interval is exponential backoff
12997
+ }
12999
12998
  });
13000
12999
  }
13001
13000
 
@@ -13167,7 +13166,6 @@ function getPushedEvents(options) {
13167
13166
 
13168
13167
  },{"../../helpers":3,"./pubnubClientWrapper":26,"agentkeepalive":36,"q":46,"superagent":49}],26:[function(require,module,exports){
13169
13168
  var pubNub = require("pubnub");
13170
- var request = require('superagent');
13171
13169
  var EventEmitter = require("events").EventEmitter;
13172
13170
  var helpers = require('../../helpers');
13173
13171
 
@@ -13190,13 +13188,6 @@ module.exports = function () {
13190
13188
  var _globalSubscription = [];
13191
13189
  var _globalSubscriptionStatus = {};
13192
13190
  var bStatusSubscribed = false;
13193
- /** ID of the setTimeout - used for Polling events when PubNub fails */
13194
- var _setTimeoutIDForPolling;
13195
- /** Timestamp from when the events need to be fetched */
13196
- var _startTimestampForPolling;
13197
- /** Counter for polling */
13198
- var _pollingCounter;
13199
- var bPollingInitiated = false;
13200
13191
 
13201
13192
  /** ###### END OF MODULE GLOBALS */
13202
13193
 
@@ -13212,9 +13203,6 @@ module.exports = function () {
13212
13203
  //Returning the adaptor (Plain Javascript object)
13213
13204
  return {
13214
13205
  "on": function (channelObj, handler) {
13215
- // If PubNub fails, we will fetch the events from this timestamp
13216
- _startTimestampForPolling = Date.now();
13217
-
13218
13206
  var pubNubChannel;
13219
13207
  var channelContext = [];
13220
13208
 
@@ -13243,9 +13231,6 @@ module.exports = function () {
13243
13231
  _eventEmitter.on(channelObj.channel, handler);
13244
13232
  bStatusSubscribed = true;
13245
13233
  }
13246
-
13247
- // Clean up the old events
13248
- _checkOldBubbledEvents();
13249
13234
  },
13250
13235
  "getMySubscriptionStatus": __getMySubscriptionStatus
13251
13236
  };
@@ -13259,10 +13244,6 @@ module.exports = function () {
13259
13244
 
13260
13245
  var _translatePubnubStatus = function(status, options) {
13261
13246
  var channels = [], error, successObj;
13262
-
13263
- // If polling has been initiated, ignore all punnub status
13264
- if (bPollingInitiated) return;
13265
-
13266
13247
  switch (status.category) {
13267
13248
  case "PNConnectedCategory":
13268
13249
  if(status.operation === "PNSubscribeOperation") {
@@ -13324,10 +13305,11 @@ module.exports = function () {
13324
13305
  break;
13325
13306
  case "PNNetworkIssuesCategory":
13326
13307
  if(status.operation === 'PNSubscribeOperation') {
13327
- if(!options.accountId || !_userOptions.pollingEndpoint) {
13308
+ if(!options.accountId) {
13328
13309
  error = {
13329
- message: "Polling initiation error: Missing mandatory parameters to initiate polling operation - [accountId, pollingEndpoint]",
13330
- status: status.statusCode
13310
+ message: "Missing mandatory parameters to initiate polling operation - accountId",
13311
+ status: status.statusCode,
13312
+ type: helpers.errors.ERROR_TYPES.POLLING_INITIATION,
13331
13313
  };
13332
13314
  error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
13333
13315
  _eventEmitter.emit('pushx_status', error);
@@ -13341,9 +13323,6 @@ module.exports = function () {
13341
13323
  * The wrapper supports multiple channels, but the APP currently uses a single channel only.
13342
13324
  * Polling will also limited to a single channel.
13343
13325
  */
13344
- _pollingCounter = 0;
13345
- _pollForEvents();
13346
- bPollingInitiated = true;
13347
13326
  }
13348
13327
  }
13349
13328
  else {
@@ -13356,8 +13335,9 @@ module.exports = function () {
13356
13335
  default:
13357
13336
  // Emit error for other status-category received from pubnub
13358
13337
  error = {
13359
- message: "PushX Error: unexpected error",
13338
+ message: "PushX Error",
13360
13339
  status: status.statusCode,
13340
+ type: helpers.errors.ERROR_TYPES.UNEXPECTED_ERROR,
13361
13341
  pushXError: status
13362
13342
  };
13363
13343
  error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
@@ -13394,7 +13374,6 @@ module.exports = function () {
13394
13374
  * @returns PROMISE.
13395
13375
  */
13396
13376
  var __setup = function (userOptions) {
13397
-
13398
13377
  var pubnubConfig = userOptions.pubnub;
13399
13378
  pubnubConfig.uuid = userOptions.userid;
13400
13379
  var accountId = userOptions.accountid;
@@ -13433,169 +13412,8 @@ module.exports = function () {
13433
13412
  _globalSubscription = [];
13434
13413
  bStatusSubscribed = false;
13435
13414
  _globalSubscriptionStatus = {};
13436
- bPollingInitiated = false;
13437
13415
  }
13438
13416
  _pubnubClient = undefined;
13439
-
13440
- // Clear the Polling
13441
- if (_setTimeoutIDForPolling) {
13442
- clearTimeout(_setTimeoutIDForPolling);
13443
- // Setting the start time to now to clear the old events
13444
- _startTimestampForPolling = Date.now();
13445
- _checkOldBubbledEvents();
13446
- _setTimeoutIDForPolling = undefined;
13447
- _pollingCounter = undefined;
13448
- _startTimestampForPolling = undefined;
13449
- }
13450
- };
13451
-
13452
- /**
13453
- * Polling function
13454
- */
13455
- var _pollForEvents = function () {
13456
- // Setup request params
13457
- var params = {
13458
- accountid: _userOptions.accountid,
13459
- channelname: _globalSubscription[0],
13460
- starttime: _startTimestampForPolling,
13461
- endtime: Date.now()
13462
- };
13463
-
13464
- // Safe check to avoid poll for events if the channel name or start time is not set
13465
- // This handles an edge condition where the clearTimeout doesn't work as expected
13466
- if (!params.channelname || !params.starttime) {
13467
- return;
13468
- }
13469
-
13470
- var requestAPI = request.get(_userOptions.pollingEndpoint).query(params);
13471
-
13472
- requestAPI
13473
- .end(function(error, response) {
13474
-
13475
- if (!error) {
13476
- // Bubble the connected status
13477
- if (_pollingCounter === 0) {
13478
- // Set the status of the channel to subscribed
13479
- if(_globalSubscriptionStatus[_globalSubscription[0]]) {
13480
- _globalSubscriptionStatus[_globalSubscription[0]].status = 'subscribed';
13481
- }
13482
-
13483
- var successObj = {
13484
- category: 'PUSHX',
13485
- type: 'CHANNEL_SUBSCRIPTION',
13486
- status: 'SUCCESS',
13487
- message: 'Success: Subscribed successfully.',
13488
- httpcode: 200,
13489
- data: {
13490
- payload: {
13491
- channels: _globalSubscription
13492
- },
13493
- message: 'Success: Subscribed successfully.'
13494
- }
13495
- };
13496
- _eventEmitter.emit('pushx_status', successObj);
13497
- }
13498
-
13499
- // Bubble the received events
13500
- _bubblePolledEvents(response.body);
13501
-
13502
- // Increase the counter
13503
- _pollingCounter++;
13504
- }
13505
-
13506
- // Polling will be done only for specific number of times
13507
- if (_pollingCounter > _userOptions.pollingIterations) {
13508
- var error = {
13509
- message: "Polling error: Polling limit exceeded",
13510
- status: 429
13511
- };
13512
- error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
13513
- _eventEmitter.emit('pushx_status', error);
13514
- } else {
13515
- var timeoutDelay;
13516
-
13517
- // If the polling interval is provided, use that
13518
- if (_userOptions.pollingInterval) {
13519
- timeoutDelay = _userOptions.pollingInterval * 60 * 1000;
13520
- } else {
13521
- // Else, use exponential backoff
13522
- timeoutDelay = parseInt(Math.pow(1.3, _pollingCounter) * 10 * 1000, 10);
13523
- }
13524
-
13525
- // Set timeout for next poll
13526
- if (timeoutDelay) {
13527
- _setTimeoutIDForPolling = setTimeout(_pollForEvents, timeoutDelay);
13528
- }
13529
- }
13530
- });
13531
- };
13532
-
13533
- /**
13534
- * Bubble the polled events to the FE APP
13535
- * @param {*} events - Events recieved from the polling endpoint
13536
- */
13537
- var _bubblePolledEvents = function (events) {
13538
- // Load the old events from the session storage
13539
- var oldEventData = _checkOldBubbledEvents();
13540
-
13541
- var oldEvents = oldEventData.events;
13542
- var sessionStorageKey = oldEventData.key;
13543
-
13544
- for (var i = 0; i < events.entities.length; i++) {
13545
- var event = events.entities[i];
13546
- var eventId = event.pk + '_' + event.sk;
13547
-
13548
- // Check if the event is already emitted
13549
- if (!oldEvents[eventId]) {
13550
- oldEvents[eventId] = event.context.start_time;
13551
-
13552
- // Emit the event
13553
- _eventEmitter.emit(_globalSubscription[0], event);
13554
- }
13555
- }
13556
-
13557
- // Save the bubbled events to session storage
13558
- sessionStorage.setItem(sessionStorageKey, JSON.stringify(oldEvents));
13559
- };
13560
-
13561
- /**
13562
- * Check the old bubbled events and remove the events that are older than the start timestamp
13563
- * @returns {object} - Object containing the key and the events
13564
- */
13565
- var _checkOldBubbledEvents = function () {
13566
- var sessionStorageKey = 'comprodls.old_pushx_events.' + _userOptions.userid + '.' + _globalSubscription[0];
13567
- var oldEvents = sessionStorage.getItem(sessionStorageKey);
13568
-
13569
- if (oldEvents) {
13570
- try {
13571
- oldEvents = JSON.parse(oldEvents);
13572
- } catch (e) {
13573
- oldEvents = {};
13574
- }
13575
-
13576
- var oldEventIds = Object.keys(oldEvents);
13577
-
13578
- // Remove the events that are older than the start timestamp
13579
- for (var i = 0; i < oldEventIds.length; i++) {
13580
- var oldEventId = oldEventIds[i];
13581
-
13582
- if (oldEvents[oldEventId] < _startTimestampForPolling) {
13583
- delete oldEvents[oldEventId];
13584
- }
13585
- }
13586
-
13587
- // If the number of events has changed, save the events
13588
- if (oldEventIds.length !== Object.keys(oldEvents).length) {
13589
- sessionStorage.setItem(sessionStorageKey, JSON.stringify(oldEvents));
13590
- }
13591
- } else {
13592
- oldEvents = {};
13593
- }
13594
-
13595
- return {
13596
- key: sessionStorageKey,
13597
- events: oldEvents
13598
- };
13599
13417
  };
13600
13418
 
13601
13419
  return { // Return public methods for the wrapper
@@ -13605,7 +13423,7 @@ module.exports = function () {
13605
13423
 
13606
13424
  }; //End of Client Wrapper module
13607
13425
 
13608
- },{"../../helpers":3,"events":41,"pubnub":45,"superagent":49}],27:[function(require,module,exports){
13426
+ },{"../../helpers":3,"events":41,"pubnub":45}],27:[function(require,module,exports){
13609
13427
  /*************************************************************************
13610
13428
  *
13611
13429
  * COMPRO CONFIDENTIAL