comprodls-sdk 2.76.0 → 2.77.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.
package/lib/config/index.js
CHANGED
|
@@ -351,6 +351,7 @@ exports.PUB_API_URLS = {
|
|
|
351
351
|
exports.PUSHX_API_URLS = {
|
|
352
352
|
grantByUserOrgId: '/orgs/{orgId}/grants',
|
|
353
353
|
grantByAccountId: '/accounts/{accountId}/grants',
|
|
354
|
+
grantV2: '/ver/v2/grants',
|
|
354
355
|
getPushedEvents: '/accounts/{accountId}/pushed-events/channels'
|
|
355
356
|
};
|
|
356
357
|
|
|
@@ -46,15 +46,16 @@ var keepaliveAgent = new Agent({
|
|
|
46
46
|
* Public Function definitions
|
|
47
47
|
**********************************/
|
|
48
48
|
function pushX() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
var _pubnubClientWrapper = pubnubClientWrapper();
|
|
50
|
+
return {
|
|
51
|
+
"connect": _connect.bind(this, _pubnubClientWrapper),
|
|
52
|
+
"cleanup": _cleanup.bind(this, _pubnubClientWrapper),
|
|
53
|
+
"grantByUserOrgId": grantByUserOrgId.bind(this),
|
|
54
|
+
"grantByAccountId": grantByAccountId.bind(this),
|
|
55
|
+
"grantByAccountIdOnExtUserId": grantByAccountIdOnExtUserId.bind(this),
|
|
56
|
+
"grantV2": grantV2.bind(this),
|
|
57
|
+
"getPushedEvents": getPushedEvents.bind(this)
|
|
58
|
+
};
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/*********************************
|
|
@@ -62,146 +63,144 @@ function pushX() {
|
|
|
62
63
|
**********************************/
|
|
63
64
|
|
|
64
65
|
function _connect(pubnubCW, options) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
|
|
67
|
+
if (bpubnubV7 && !options.userid) {
|
|
68
|
+
var err = {};
|
|
69
|
+
err.message = err.description = 'Mandatory parameter userid not found in request options.';
|
|
70
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.PUSHX_ERROR, err);
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
// Adding SSL flag
|
|
75
|
+
return pubnubCW.setup({
|
|
76
|
+
'userid': options.userid,
|
|
77
|
+
'accountid': options.accountid,
|
|
78
|
+
'token': options.token,
|
|
79
|
+
'pubnub': {
|
|
80
|
+
'publishKey': options.publishKey,
|
|
81
|
+
'subscribeKey': options.subscribeKey,
|
|
82
|
+
'ssl': true
|
|
83
|
+
}
|
|
84
|
+
});
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
function _cleanup(pubnubCW) { pubnubCW.cleanup(); }
|
|
87
88
|
|
|
88
|
-
/*options = {
|
|
89
|
-
authKey: <authKey>
|
|
90
|
-
}*/
|
|
89
|
+
/*options = {}*/
|
|
91
90
|
function grantByUserOrgId(options) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
//Setup token in Authorization header
|
|
112
|
-
requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
|
|
113
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
114
|
-
|
|
115
|
-
// Call Change Password Api
|
|
116
|
-
requestAPI.end(function(err, response) {
|
|
117
|
-
if(err) {
|
|
118
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
119
|
-
dfd.reject(err);
|
|
120
|
-
}
|
|
121
|
-
else { dfd.resolve(response.body); }
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return dfd.promise;
|
|
91
|
+
var dfd = q.defer(); // Initializing promise
|
|
92
|
+
var allowedChannels = ['jobs', 'systemevents'];
|
|
93
|
+
var baseChannelName = "o-" + this.orgId + "\\$u-" + this.token.access_token + "\\$";
|
|
94
|
+
var patterns = [];
|
|
95
|
+
for(var i in allowedChannels) {
|
|
96
|
+
var channelName = baseChannelName + allowedChannels[i] + "\\..*";
|
|
97
|
+
patterns.push(channelName);
|
|
98
|
+
}
|
|
99
|
+
options.channels = {};
|
|
100
|
+
options.channels.patterns = patterns;
|
|
101
|
+
grantV2.call(this, options)
|
|
102
|
+
.then(function (res) {
|
|
103
|
+
dfd.resolve(res);
|
|
104
|
+
})
|
|
105
|
+
.catch(function(err) {
|
|
106
|
+
dfd.reject(err);
|
|
107
|
+
});
|
|
108
|
+
return dfd.promise;
|
|
125
109
|
}
|
|
126
110
|
|
|
127
111
|
/*options = {
|
|
128
112
|
accountId: <accountid>,
|
|
129
|
-
refId: <extRefId
|
|
130
|
-
authKey: <authKey>
|
|
113
|
+
refId: <extRefId>
|
|
131
114
|
}*/
|
|
132
115
|
function grantByAccountId(options) {
|
|
133
|
-
var
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
err.message = err.description = "Required parameter ['accountId', 'refId'] " +
|
|
160
|
-
"not found in request options";
|
|
161
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
162
|
-
dfd.reject(err);
|
|
163
|
-
}
|
|
164
|
-
return dfd.promise;
|
|
116
|
+
var err ={};
|
|
117
|
+
var dfd = q.defer(); // Initializing promise
|
|
118
|
+
|
|
119
|
+
if(options.accountId && options.refId) {
|
|
120
|
+
var channel = "a-" + options.accountId + "$refid." + options.refId;
|
|
121
|
+
var exactMatch = [channel];
|
|
122
|
+
options.channels = {};
|
|
123
|
+
options.channels.exactMatch = exactMatch;
|
|
124
|
+
grantV2.call(this, options)
|
|
125
|
+
.then(function (res) {
|
|
126
|
+
dfd.resolve(res);
|
|
127
|
+
})
|
|
128
|
+
.catch(function(err) {
|
|
129
|
+
dfd.reject(err);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
err.message = err.description = "Required parameter ['accountId', 'refId'] " +
|
|
134
|
+
"not found in request options";
|
|
135
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
136
|
+
dfd.reject(err);
|
|
137
|
+
}
|
|
138
|
+
return dfd.promise;
|
|
165
139
|
}
|
|
166
140
|
|
|
167
141
|
/*options = {
|
|
168
142
|
accountId: <accountid>,
|
|
169
143
|
extUserId: <extUserId>, //mandatory
|
|
170
|
-
authKey: <authKey>
|
|
171
144
|
}*/
|
|
172
145
|
function grantByAccountIdOnExtUserId(options) {
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
146
|
+
var err ={};
|
|
147
|
+
var dfd = q.defer(); // Initializing promise
|
|
148
|
+
|
|
149
|
+
if(options.accountId && options.extUserId) {
|
|
150
|
+
var channel = "a-" + options.accountId + "$u-" + options.extUserId;
|
|
151
|
+
var exactMatch = [channel];
|
|
152
|
+
options.channels = {};
|
|
153
|
+
options.channels.exactMatch = exactMatch;
|
|
154
|
+
grantV2.call(this, options)
|
|
155
|
+
.then(function (res) {
|
|
156
|
+
dfd.resolve(res);
|
|
157
|
+
})
|
|
158
|
+
.catch(function(err) {
|
|
159
|
+
dfd.reject(err);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
|
|
164
|
+
"not found in request options";
|
|
165
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
166
|
+
dfd.reject(err);
|
|
167
|
+
}
|
|
168
|
+
return dfd.promise;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* This function provides grant token on given channels
|
|
173
|
+
* @param { channels: { exactMatch: [], patterns: [] } } options
|
|
174
|
+
* @returns { token, publishKey, subscribeKey }
|
|
175
|
+
*/
|
|
176
|
+
function grantV2(options) {
|
|
177
|
+
var self = this, err = {};
|
|
178
|
+
var dfd = q.defer();
|
|
179
|
+
var body = { channels: {} };
|
|
180
|
+
if(!options.channels) {
|
|
181
|
+
err.message = err.description = "channels not given in input body.";
|
|
182
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
183
|
+
dfd.reject(err);
|
|
204
184
|
return dfd.promise;
|
|
185
|
+
}
|
|
186
|
+
body.channels = options.channels;
|
|
187
|
+
// Passed all validations, Construct API url
|
|
188
|
+
var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantV2;
|
|
189
|
+
// Setup request with URL and Params
|
|
190
|
+
var requestAPI = request.post(url)
|
|
191
|
+
.set('Content-Type', 'application/json')
|
|
192
|
+
.set('Accept', 'application/json');
|
|
193
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
194
|
+
|
|
195
|
+
requestAPI.send(body);
|
|
196
|
+
requestAPI.end(function(err, response) {
|
|
197
|
+
if(err) {
|
|
198
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
199
|
+
dfd.reject(err);
|
|
200
|
+
}
|
|
201
|
+
else { dfd.resolve(response.body); }
|
|
202
|
+
});
|
|
203
|
+
return dfd.promise;
|
|
205
204
|
}
|
|
206
205
|
|
|
207
206
|
/**
|
|
@@ -55,8 +55,7 @@ module.exports = function () {
|
|
|
55
55
|
if(!_globalSubscription.includes(pubNubChannel)) {
|
|
56
56
|
_globalSubscription.push(pubNubChannel);
|
|
57
57
|
_globalSubscriptionStatus[pubNubChannel] = {
|
|
58
|
-
status: 'pending'
|
|
59
|
-
pushedEventIdentifier: pubNubChannel.split('.*')[0]
|
|
58
|
+
status: 'pending'
|
|
60
59
|
};
|
|
61
60
|
_eventEmitter.on(pubNubChannel, handler);
|
|
62
61
|
_subscribeToPubNubChannels(pubNubChannel);
|
|
@@ -79,6 +78,10 @@ module.exports = function () {
|
|
|
79
78
|
|
|
80
79
|
var _translatePubnubStatus = function(status, options) {
|
|
81
80
|
var channels = [], error, successObj;
|
|
81
|
+
|
|
82
|
+
// If polling has been initiated, ignore all punnub status
|
|
83
|
+
if (bPollingInitiated) return;
|
|
84
|
+
|
|
82
85
|
switch (status.category) {
|
|
83
86
|
case "PNConnectedCategory":
|
|
84
87
|
if(status.operation === "PNSubscribeOperation") {
|
|
@@ -105,10 +108,11 @@ module.exports = function () {
|
|
|
105
108
|
}
|
|
106
109
|
break;
|
|
107
110
|
case "PNAccessDeniedCategory":
|
|
108
|
-
if(bPollingInitiated) break;
|
|
109
111
|
if(status.operation === "PNSubscribeOperation") {
|
|
112
|
+
var errorText = status.errorData.response && status.errorData.response.text;
|
|
113
|
+
var errorJSON = errorText ? JSON.parse(errorText) : undefined;
|
|
110
114
|
var errorData = {
|
|
111
|
-
payload:
|
|
115
|
+
payload: errorJSON && errorJSON.payload || status.errorData.payload,
|
|
112
116
|
message: 'Forbidden: Subscription failed.',
|
|
113
117
|
errorDetails: {
|
|
114
118
|
operation: status.operation,
|
|
@@ -130,7 +134,6 @@ module.exports = function () {
|
|
|
130
134
|
case "PNBadRequestCategory":
|
|
131
135
|
case "PNNetworkDownCategory":
|
|
132
136
|
case "PNNetworkUpCategory":
|
|
133
|
-
if(bPollingInitiated) break;
|
|
134
137
|
error = {
|
|
135
138
|
message: "PushX Error", status: status.statusCode,
|
|
136
139
|
pushXError: status
|
|
@@ -169,7 +172,6 @@ module.exports = function () {
|
|
|
169
172
|
// Handle reconnected category status.
|
|
170
173
|
break;
|
|
171
174
|
default:
|
|
172
|
-
if(bPollingInitiated) break;
|
|
173
175
|
// Emit error for other status-category received from pubnub
|
|
174
176
|
error = {
|
|
175
177
|
message: "PushX Error",
|
|
@@ -214,9 +216,11 @@ module.exports = function () {
|
|
|
214
216
|
var pubnubConfig = userOptions.pubnub;
|
|
215
217
|
pubnubConfig.uuid = userOptions.userid;
|
|
216
218
|
var accountId = userOptions.accountid;
|
|
219
|
+
var token = userOptions.token;
|
|
217
220
|
|
|
218
221
|
if (!_pubnubClient && pubnubConfig) {
|
|
219
222
|
_pubnubClient = new pubNub(pubnubConfig); //Connect with PubNub SDK
|
|
223
|
+
_pubnubClient.setToken(token);
|
|
220
224
|
processSetup();
|
|
221
225
|
} else {
|
|
222
226
|
return new Error('Already Initialized');
|
|
@@ -247,6 +251,7 @@ module.exports = function () {
|
|
|
247
251
|
_globalSubscription = [];
|
|
248
252
|
bStatusSubscribed = false;
|
|
249
253
|
_globalSubscriptionStatus = {};
|
|
254
|
+
bPollingInitiated = false;
|
|
250
255
|
}
|
|
251
256
|
_pubnubClient = undefined;
|
|
252
257
|
};
|