comprodls-sdk 2.74.1 → 2.75.2

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.
@@ -504,6 +504,7 @@ exports.PUB_API_URLS = {
504
504
  exports.PUSHX_API_URLS = {
505
505
  grantByUserOrgId: '/orgs/{orgId}/grants',
506
506
  grantByAccountId: '/accounts/{accountId}/grants',
507
+ grantV2: '/ver/v2/grants',
507
508
  getPushedEvents: '/accounts/{accountId}/pushed-events/channels'
508
509
  };
509
510
 
@@ -12827,15 +12828,16 @@ var keepaliveAgent = new Agent({
12827
12828
  * Public Function definitions
12828
12829
  **********************************/
12829
12830
  function pushX() {
12830
- var _pubnubClientWrapper = pubnubClientWrapper();
12831
- return {
12832
- "connect": _connect.bind(this, _pubnubClientWrapper),
12833
- "cleanup": _cleanup.bind(this, _pubnubClientWrapper),
12834
- "grantByUserOrgId": grantByUserOrgId.bind(this),
12835
- "grantByAccountId": grantByAccountId.bind(this),
12836
- "grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this),
12837
- "getPushedEvents": getPushedEvents.bind(this)
12838
- };
12831
+ var _pubnubClientWrapper = pubnubClientWrapper();
12832
+ return {
12833
+ "connect": _connect.bind(this, _pubnubClientWrapper),
12834
+ "cleanup": _cleanup.bind(this, _pubnubClientWrapper),
12835
+ "grantByUserOrgId": grantByUserOrgId.bind(this),
12836
+ "grantByAccountId": grantByAccountId.bind(this),
12837
+ "grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this),
12838
+ "grantV2": grantV2.bind(this),
12839
+ "getPushedEvents": getPushedEvents.bind(this)
12840
+ };
12839
12841
  }
12840
12842
 
12841
12843
  /*********************************
@@ -12843,146 +12845,147 @@ function pushX() {
12843
12845
  **********************************/
12844
12846
 
12845
12847
  function _connect(pubnubCW, options) {
12846
- var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
12847
- if (bpubnubV7 && !options.userid) {
12848
- var err = {};
12849
- err.message = err.description = 'Mandatory parameter userid not found in request options.';
12850
- err = new DLSError(helpers.errors.ERROR_TYPES.PUSHX_ERROR, err);
12851
- throw err;
12852
- }
12853
-
12854
- // Adding SSL flag
12855
- return pubnubCW.setup({
12856
- 'userid': options.userid,
12857
- 'accountid': options.accountid,
12858
- 'pubnub': {
12859
- 'publishKey': options.publishKey,
12860
- 'subscribeKey': options.subscribeKey,
12861
- 'authKey': options.authKey,
12862
- 'ssl': true
12863
- }
12864
- });
12848
+ var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
12849
+ if (bpubnubV7 && !options.userid) {
12850
+ var err = {};
12851
+ err.message = err.description = 'Mandatory parameter userid not found in request options.';
12852
+ err = new DLSError(helpers.errors.ERROR_TYPES.PUSHX_ERROR, err);
12853
+ throw err;
12854
+ }
12855
+
12856
+ // Adding SSL flag
12857
+ return pubnubCW.setup({
12858
+ 'userid': options.userid,
12859
+ 'accountid': options.accountid,
12860
+ 'token': options.token,
12861
+ 'pubnub': {
12862
+ 'publishKey': options.publishKey,
12863
+ 'subscribeKey': options.subscribeKey,
12864
+ 'ssl': true
12865
+ }
12866
+ });
12865
12867
  }
12866
12868
 
12867
12869
  function _cleanup(pubnubCW) { pubnubCW.cleanup(); }
12868
12870
 
12869
12871
  /*options = {
12870
- authKey: <authKey>
12872
+ orgId: <orgId>, userId: <userId>
12871
12873
  }*/
12872
12874
  function grantByUserOrgId(options) {
12873
- var self = this;
12874
- var dfd = q.defer(); // Initializing promise
12875
- // Validations
12876
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
12877
- if(err) { dfd.reject(err); }
12878
- else {
12879
- // Passed all validations, Construct API url
12880
- var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantByUserOrgId;
12881
- url = helpers.api.constructAPIUrl(url, { orgId: self.orgId });
12882
- // Setup request with URL and Params
12883
- var requestAPI = request.post(url)
12884
- .set('Content-Type', 'application/json')
12885
- .set('Accept', 'application/json');
12886
-
12887
- var body = {};
12888
- if(options.authKey) { body.authKey = options.authKey; }
12889
-
12890
- requestAPI.send(body);
12891
-
12892
- //Setup token in Authorization header
12893
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
12894
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
12895
-
12896
- // Call Change Password Api
12897
- requestAPI.end(function(err, response) {
12898
- if(err) {
12899
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
12900
- dfd.reject(err);
12901
- }
12902
- else { dfd.resolve(response.body); }
12903
- });
12904
- }
12905
- return dfd.promise;
12875
+ var dfd = q.defer(); // Initializing promise
12876
+ var allowedChannels = ['jobs', 'systemevents'];
12877
+ var baseChannelName = "o-" + options.orgId + "\\$u-" + options.userId + "\\$";
12878
+ var patterns = [];
12879
+ for(var i in allowedChannels) {
12880
+ var channelName = baseChannelName + allowedChannels[i] + "\\..*";
12881
+ patterns.push(channelName);
12882
+ }
12883
+ console.log("0a781d69 TAKING GRANT FOR CHANNEL PATTERNS: ", patterns);
12884
+ options.channels = {};
12885
+ options.channels.patterns = patterns;
12886
+ grantV2.call(this, options)
12887
+ .then(function (res) {
12888
+ dfd.resolve(res);
12889
+ })
12890
+ .catch(function(err) {
12891
+ dfd.reject(err);
12892
+ });
12893
+ return dfd.promise;
12906
12894
  }
12907
12895
 
12908
12896
  /*options = {
12909
12897
  accountId: <accountid>,
12910
- refId: <extRefId>,
12911
- authKey: <authKey>
12898
+ refId: <extRefId>
12912
12899
  }*/
12913
12900
  function grantByAccountId(options) {
12914
- var self = this, err ={};
12915
- var dfd = q.defer(); // Initializing promise
12916
-
12917
- if(options.accountId && options.refId) {
12918
- // Passed all validations, Construct API url
12919
- var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantByAccountId;
12920
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountId });
12921
- // Setup request with URL and Params
12922
- var requestAPI = request.post(url)
12923
- .set('Content-Type', 'application/json')
12924
- .set('Accept', 'application/json');
12925
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
12926
-
12927
- var body = { refId: options.refId };
12928
- if(options.authKey) { body.authKey = options.authKey; }
12901
+ var err ={};
12902
+ var dfd = q.defer(); // Initializing promise
12929
12903
 
12930
- requestAPI.send(body);
12931
- requestAPI.end(function(err, response) {
12932
- if(err) {
12933
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
12934
- dfd.reject(err);
12935
- }
12936
- else { dfd.resolve(response.body); }
12937
- });
12938
- }
12939
- else {
12940
- err.message = err.description = "Required parameter ['accountId', 'refId'] " +
12941
- "not found in request options";
12942
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
12943
- dfd.reject(err);
12944
- }
12945
- return dfd.promise;
12904
+ if(options.accountId && options.refId) {
12905
+ var channel = "a-" + options.accountId + "$refid." + options.refId;
12906
+ var exactMatch = [channel];
12907
+ options.channels = {};
12908
+ options.channels.exactMatch = exactMatch;
12909
+ grantV2.call(this, options)
12910
+ .then(function (res) {
12911
+ dfd.resolve(res);
12912
+ })
12913
+ .catch(function(err) {
12914
+ dfd.reject(err);
12915
+ });
12916
+ }
12917
+ else {
12918
+ err.message = err.description = "Required parameter ['accountId', 'refId'] " +
12919
+ "not found in request options";
12920
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
12921
+ dfd.reject(err);
12922
+ }
12923
+ return dfd.promise;
12946
12924
  }
12947
12925
 
12948
12926
  /*options = {
12949
12927
  accountId: <accountid>,
12950
12928
  extUserId: <extUserId>, //mandatory
12951
- authKey: <authKey>
12952
12929
  }*/
12953
12930
  function grantByAccountIdOnExtUserId(options) {
12954
- var self = this, err ={};
12955
- var dfd = q.defer(); // Initializing promise
12931
+ var err ={};
12932
+ var dfd = q.defer(); // Initializing promise
12956
12933
 
12957
- if(options.accountId && options.extUserId) {
12958
- // Passed all validations, Construct API url
12959
- var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantByAccountId;
12960
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountId });
12961
- // Setup request with URL and Params
12962
- var requestAPI = request.post(url)
12963
- .set('Content-Type', 'application/json')
12964
- .set('Accept', 'application/json');
12965
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
12934
+ if(options.accountId && options.extUserId) {
12935
+ var channel = "a-" + options.accountId + "$u-" + options.extUserId;
12936
+ var exactMatch = [channel];
12937
+ options.channels = {};
12938
+ options.channels.exactMatch = exactMatch;
12939
+ grantV2.call(this, options)
12940
+ .then(function (res) {
12941
+ dfd.resolve(res);
12942
+ })
12943
+ .catch(function(err) {
12944
+ dfd.reject(err);
12945
+ });
12946
+ }
12947
+ else {
12948
+ err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
12949
+ "not found in request options";
12950
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
12951
+ dfd.reject(err);
12952
+ }
12953
+ return dfd.promise;
12954
+ }
12966
12955
 
12967
- var body = { extUserId: options.extUserId };
12968
- if(options.authKey) { body.authKey = options.authKey; }
12956
+ /**
12957
+ * This function provides grant token on given channels
12958
+ * @param { channels: { exactMatch: [], patterns: [] } } options
12959
+ * @returns { token, publishKey, subscribeKey }
12960
+ */
12961
+ function grantV2(options) {
12962
+ var self = this, err = {};
12963
+ var dfd = q.defer();
12964
+ var body = { channels: {} };
12965
+ if(!options.channels) {
12966
+ err.message = err.description = "channels not given in input body.";
12967
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
12968
+ dfd.reject(err);
12969
+ return dfd.promise;
12970
+ }
12971
+ body.channels = options.channels;
12972
+ // Passed all validations, Construct API url
12973
+ var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantV2;
12974
+ // Setup request with URL and Params
12975
+ var requestAPI = request.post(url)
12976
+ .set('Content-Type', 'application/json')
12977
+ .set('Accept', 'application/json');
12978
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
12969
12979
 
12970
- requestAPI.send(body);
12971
- requestAPI.end(function(err, response) {
12972
- if(err) {
12973
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
12974
- dfd.reject(err);
12975
- }
12976
- else { dfd.resolve(response.body); }
12977
- });
12978
- }
12979
- else {
12980
- err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
12981
- "not found in request options";
12982
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
12983
- dfd.reject(err);
12980
+ requestAPI.send(body);
12981
+ requestAPI.end(function(err, response) {
12982
+ if(err) {
12983
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
12984
+ dfd.reject(err);
12984
12985
  }
12985
- return dfd.promise;
12986
+ else { dfd.resolve(response.body); }
12987
+ });
12988
+ return dfd.promise;
12986
12989
  }
12987
12990
 
12988
12991
  /**
@@ -13071,6 +13074,7 @@ module.exports = function () {
13071
13074
  //Returning the adaptor (Plain Javascript object)
13072
13075
  return {
13073
13076
  "on": function (channelObj, handler) {
13077
+ console.log("0a781d69 PARAMS OF .on FUNCTION: ", JSON.stringify(channelObj, null, 2));
13074
13078
  var pubNubChannel;
13075
13079
  var channelContext = [];
13076
13080
 
@@ -13092,6 +13096,7 @@ module.exports = function () {
13092
13096
  status: 'pending'
13093
13097
  };
13094
13098
  _eventEmitter.on(pubNubChannel, handler);
13099
+ console.log("0a781d69 GOING TO SUBSCRIBE ON PUBNUB CHANNEL: ", pubNubChannel);
13095
13100
  _subscribeToPubNubChannels(pubNubChannel);
13096
13101
  }
13097
13102
  }
@@ -13112,6 +13117,7 @@ module.exports = function () {
13112
13117
 
13113
13118
  var _translatePubnubStatus = function(status, options) {
13114
13119
  var channels = [], error, successObj;
13120
+ console.log('0a781d69 PUBNUB STATUS: ', JSON.stringify(status, null, 4));
13115
13121
  switch (status.category) {
13116
13122
  case "PNConnectedCategory":
13117
13123
  if(status.operation === "PNSubscribeOperation") {
@@ -13139,8 +13145,10 @@ module.exports = function () {
13139
13145
  break;
13140
13146
  case "PNAccessDeniedCategory":
13141
13147
  if(status.operation === "PNSubscribeOperation") {
13148
+ var errorText = status.errorData.response && status.errorData.response.text;
13149
+ var errorJSON = errorText ? JSON.parse(errorText) : undefined;
13142
13150
  var errorData = {
13143
- payload: JSON.parse(status.errorData.response.text).payload,
13151
+ payload: errorJSON && errorJSON.payload || status.errorData.payload,
13144
13152
  message: 'Forbidden: Subscription failed.',
13145
13153
  errorDetails: {
13146
13154
  operation: status.operation,
@@ -13243,10 +13251,17 @@ module.exports = function () {
13243
13251
  var pubnubConfig = userOptions.pubnub;
13244
13252
  pubnubConfig.uuid = userOptions.userid;
13245
13253
  var accountId = userOptions.accountid;
13254
+ var token = userOptions.token;
13246
13255
 
13247
13256
  if (!_pubnubClient && pubnubConfig) {
13248
- _pubnubClient = new pubNub(pubnubConfig); //Connect with PubNub SDK
13249
- processSetup();
13257
+ try {
13258
+ _pubnubClient = new pubNub(pubnubConfig); //Connect with PubNub SDK
13259
+ _pubnubClient.setToken(token);
13260
+ setTimeout(processSetup, 1000);
13261
+ processSetup();
13262
+ } catch(err) {
13263
+ console.error('0a781d69 ERROR WHILE CONFIGURING PUBNUB: ', JSON.stringify(err, null, 2));
13264
+ }
13250
13265
  } else {
13251
13266
  return new Error('Already Initialized');
13252
13267
  }