comprodls-sdk 2.77.1 → 2.79.0

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.
@@ -12860,7 +12860,10 @@ function _connect(pubnubCW, options) {
12860
12860
  'publishKey': options.publishKey,
12861
12861
  'subscribeKey': options.subscribeKey,
12862
12862
  'ssl': true
12863
- }
12863
+ },
12864
+ 'pollingEndpoint': options.pollingEndpoint,
12865
+ 'pollingIterations': options.pollingIterations || 10, // Default polling iterations is 10
12866
+ 'pollingInterval': options.pollingInterval || 1, // Default polling interval is 1 minute
12864
12867
  });
12865
12868
  }
12866
12869
 
@@ -13032,6 +13035,7 @@ function getPushedEvents(options) {
13032
13035
 
13033
13036
  },{"../../helpers":3,"./pubnubClientWrapper":26,"agentkeepalive":36,"q":42,"superagent":45}],26:[function(require,module,exports){
13034
13037
  var pubNub = require("pubnub");
13038
+ var request = require('superagent');
13035
13039
  var EventEmitter = require("events").EventEmitter;
13036
13040
  var helpers = require('../../helpers');
13037
13041
 
@@ -13054,6 +13058,12 @@ module.exports = function () {
13054
13058
  var _globalSubscription = [];
13055
13059
  var _globalSubscriptionStatus = {};
13056
13060
  var bStatusSubscribed = false;
13061
+ /** ID of the setTimeout - used for Polling events when PubNub fails */
13062
+ var _setTimeoutIDForPolling;
13063
+ /** Timestamp from when the events need to be fetched */
13064
+ var _startTimestampForPolling;
13065
+ /** Counter for polling */
13066
+ var _pollingCounter;
13057
13067
  var bPollingInitiated = false;
13058
13068
 
13059
13069
  /** ###### END OF MODULE GLOBALS */
@@ -13070,6 +13080,9 @@ module.exports = function () {
13070
13080
  //Returning the adaptor (Plain Javascript object)
13071
13081
  return {
13072
13082
  "on": function (channelObj, handler) {
13083
+ // If PubNub fails, we will fetch the events from this timestamp
13084
+ _startTimestampForPolling = Date.now();
13085
+
13073
13086
  var pubNubChannel;
13074
13087
  var channelContext = [];
13075
13088
 
@@ -13098,6 +13111,9 @@ module.exports = function () {
13098
13111
  _eventEmitter.on(channelObj.channel, handler);
13099
13112
  bStatusSubscribed = true;
13100
13113
  }
13114
+
13115
+ // Clean up the old events
13116
+ _checkOldBubbledEvents();
13101
13117
  },
13102
13118
  "getMySubscriptionStatus": __getMySubscriptionStatus
13103
13119
  };
@@ -13176,9 +13192,9 @@ module.exports = function () {
13176
13192
  break;
13177
13193
  case "PNNetworkIssuesCategory":
13178
13194
  if(status.operation === 'PNSubscribeOperation') {
13179
- if(!options.accountId) {
13195
+ if(!options.accountId || !_userOptions.pollingEndpoint) {
13180
13196
  error = {
13181
- message: "Polling initiation error: Missing mandatory parameters to initiate polling operation - accountId",
13197
+ message: "Polling initiation error: Missing mandatory parameters to initiate polling operation - [accountId, pollingEndpoint]",
13182
13198
  status: status.statusCode
13183
13199
  };
13184
13200
  error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
@@ -13193,6 +13209,8 @@ module.exports = function () {
13193
13209
  * The wrapper supports multiple channels, but the APP currently uses a single channel only.
13194
13210
  * Polling will also limited to a single channel.
13195
13211
  */
13212
+ _pollingCounter = 0;
13213
+ _pollForEvents();
13196
13214
  bPollingInitiated = true;
13197
13215
  }
13198
13216
  }
@@ -13244,6 +13262,7 @@ module.exports = function () {
13244
13262
  * @returns PROMISE.
13245
13263
  */
13246
13264
  var __setup = function (userOptions) {
13265
+
13247
13266
  var pubnubConfig = userOptions.pubnub;
13248
13267
  pubnubConfig.uuid = userOptions.userid;
13249
13268
  var accountId = userOptions.accountid;
@@ -13285,6 +13304,147 @@ module.exports = function () {
13285
13304
  bPollingInitiated = false;
13286
13305
  }
13287
13306
  _pubnubClient = undefined;
13307
+
13308
+ // Clear the Polling
13309
+ if (_setTimeoutIDForPolling) {
13310
+ clearTimeout(_setTimeoutIDForPolling);
13311
+ // Setting the start time to now to clear the old events
13312
+ _startTimestampForPolling = Date.now();
13313
+ _checkOldBubbledEvents();
13314
+ _setTimeoutIDForPolling = undefined;
13315
+ _pollingCounter = undefined;
13316
+ _startTimestampForPolling = undefined;
13317
+ }
13318
+ };
13319
+
13320
+ /**
13321
+ * Polling function
13322
+ */
13323
+ var _pollForEvents = function () {
13324
+ // Setup request params
13325
+ var params = {
13326
+ accountid: _userOptions.accountid,
13327
+ channelname: _globalSubscription[0],
13328
+ starttime: _startTimestampForPolling,
13329
+ endtime: Date.now()
13330
+ };
13331
+ var requestAPI = request.get(_userOptions.pollingEndpoint).query(params);
13332
+
13333
+ requestAPI
13334
+ .end(function(error, response) {
13335
+
13336
+ if (!error) {
13337
+ // Bubble the connected status
13338
+ if (_pollingCounter === 0) {
13339
+ // Set the status of the channel to subscribed
13340
+ if(_globalSubscriptionStatus[_globalSubscription[0]]) {
13341
+ _globalSubscriptionStatus[_globalSubscription[0]].status = 'subscribed';
13342
+ }
13343
+
13344
+ var successObj = {
13345
+ category: 'PUSHX',
13346
+ type: 'CHANNEL_SUBSCRIPTION',
13347
+ status: 'SUCCESS',
13348
+ message: 'Success: Subscribed successfully.',
13349
+ httpcode: 200,
13350
+ data: {
13351
+ payload: {
13352
+ channels: _globalSubscription
13353
+ },
13354
+ message: 'Success: Subscribed successfully.'
13355
+ }
13356
+ };
13357
+ _eventEmitter.emit('pushx_status', successObj);
13358
+ }
13359
+
13360
+ // Bubble the received events
13361
+ _bubblePolledEvents(response.body);
13362
+
13363
+ // Increase the counter
13364
+ _pollingCounter++;
13365
+ }
13366
+
13367
+ // Polling will be done only for specific number of times
13368
+ if (_pollingCounter > _userOptions.pollingIterations) {
13369
+ var error = {
13370
+ message: "Polling error: Polling limit exceeded",
13371
+ status: 429
13372
+ };
13373
+ error = new PUSHXError(helpers.errors.ERROR_CATEGORY.PUSHX, error);
13374
+ _eventEmitter.emit('pushx_status', error);
13375
+ } else {
13376
+ // Set timeout for next poll
13377
+ _setTimeoutIDForPolling = setTimeout(_pollForEvents, _userOptions.pollingInterval * 60 * 1000);
13378
+ }
13379
+ });
13380
+ };
13381
+
13382
+ /**
13383
+ * Bubble the polled events to the FE APP
13384
+ * @param {*} events - Events recieved from the polling endpoint
13385
+ */
13386
+ var _bubblePolledEvents = function (events) {
13387
+ // Load the old events from the session storage
13388
+ var oldEventData = _checkOldBubbledEvents();
13389
+
13390
+ var oldEvents = oldEventData.events;
13391
+ var sessionStorageKey = oldEventData.key;
13392
+
13393
+ for (var i = 0; i < events.entities.length; i++) {
13394
+ var event = events.entities[i];
13395
+ var eventId = event.pk + '_' + event.sk;
13396
+
13397
+ // Check if the event is already emitted
13398
+ if (!oldEvents[eventId]) {
13399
+ oldEvents[eventId] = event.context.start_time;
13400
+
13401
+ // Emit the event
13402
+ _eventEmitter.emit(_globalSubscription[0], event);
13403
+ }
13404
+ }
13405
+
13406
+ // Save the bubbled events to session storage
13407
+ sessionStorage.setItem(sessionStorageKey, JSON.stringify(oldEvents));
13408
+ };
13409
+
13410
+ /**
13411
+ * Check the old bubbled events and remove the events that are older than the start timestamp
13412
+ * @returns {object} - Object containing the key and the events
13413
+ */
13414
+ var _checkOldBubbledEvents = function () {
13415
+ var sessionStorageKey = 'comprodls.old_pushx_events.' + _userOptions.userid + '.' + _globalSubscription[0];
13416
+ var oldEvents = sessionStorage.getItem(sessionStorageKey);
13417
+
13418
+ if (oldEvents) {
13419
+ try {
13420
+ oldEvents = JSON.parse(oldEvents);
13421
+ } catch (e) {
13422
+ oldEvents = {};
13423
+ }
13424
+
13425
+ var oldEventIds = Object.keys(oldEvents);
13426
+
13427
+ // Remove the events that are older than the start timestamp
13428
+ for (var i = 0; i < oldEventIds.length; i++) {
13429
+ var oldEventId = oldEventIds[i];
13430
+
13431
+ if (oldEvents[oldEventId] < _startTimestampForPolling) {
13432
+ delete oldEvents[oldEventId];
13433
+ }
13434
+ }
13435
+
13436
+ // If the number of events has changed, save the events
13437
+ if (oldEventIds.length !== Object.keys(oldEvents).length) {
13438
+ sessionStorage.setItem(sessionStorageKey, JSON.stringify(oldEvents));
13439
+ }
13440
+ } else {
13441
+ oldEvents = {};
13442
+ }
13443
+
13444
+ return {
13445
+ key: sessionStorageKey,
13446
+ events: oldEvents
13447
+ };
13288
13448
  };
13289
13449
 
13290
13450
  return { // Return public methods for the wrapper
@@ -13294,7 +13454,7 @@ module.exports = function () {
13294
13454
 
13295
13455
  }; //End of Client Wrapper module
13296
13456
 
13297
- },{"../../helpers":3,"events":38,"pubnub":41}],27:[function(require,module,exports){
13457
+ },{"../../helpers":3,"events":38,"pubnub":41,"superagent":45}],27:[function(require,module,exports){
13298
13458
  /*************************************************************************
13299
13459
  *
13300
13460
  * COMPRO CONFIDENTIAL
@@ -14292,6 +14452,7 @@ function provisionBulkSpaces(options) {
14292
14452
  * *startdate: <epoch>,
14293
14453
  * *enddate: <epoch>,
14294
14454
  * description: 'string',
14455
+ * ext_class_title : 'string',
14295
14456
  * ext_data: {},
14296
14457
  * limits: {
14297
14458
  * *los: 0,