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.
- package/dist/comprodls-sdk.js +142 -127
- package/dist/comprodls-sdk.min.js +1 -1
- package/lib/config/index.js +1 -0
- package/lib/services/pushX/index.js +129 -127
- package/lib/services/pushX/pubnubClientWrapper.js +15 -3
- package/package.json +1 -1
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,147 @@ 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
89
|
/*options = {
|
|
89
|
-
|
|
90
|
+
orgId: <orgId>, userId: <userId>
|
|
90
91
|
}*/
|
|
91
92
|
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;
|
|
93
|
+
var dfd = q.defer(); // Initializing promise
|
|
94
|
+
var allowedChannels = ['jobs', 'systemevents'];
|
|
95
|
+
var baseChannelName = "o-" + options.orgId + "\\$u-" + options.userId + "\\$";
|
|
96
|
+
var patterns = [];
|
|
97
|
+
for(var i in allowedChannels) {
|
|
98
|
+
var channelName = baseChannelName + allowedChannels[i] + "\\..*";
|
|
99
|
+
patterns.push(channelName);
|
|
100
|
+
}
|
|
101
|
+
console.log("0a781d69 TAKING GRANT FOR CHANNEL PATTERNS: ", patterns);
|
|
102
|
+
options.channels = {};
|
|
103
|
+
options.channels.patterns = patterns;
|
|
104
|
+
grantV2.call(this, options)
|
|
105
|
+
.then(function (res) {
|
|
106
|
+
dfd.resolve(res);
|
|
107
|
+
})
|
|
108
|
+
.catch(function(err) {
|
|
109
|
+
dfd.reject(err);
|
|
110
|
+
});
|
|
111
|
+
return dfd.promise;
|
|
125
112
|
}
|
|
126
113
|
|
|
127
114
|
/*options = {
|
|
128
115
|
accountId: <accountid>,
|
|
129
|
-
refId: <extRefId
|
|
130
|
-
authKey: <authKey>
|
|
116
|
+
refId: <extRefId>
|
|
131
117
|
}*/
|
|
132
118
|
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;
|
|
119
|
+
var err ={};
|
|
120
|
+
var dfd = q.defer(); // Initializing promise
|
|
121
|
+
|
|
122
|
+
if(options.accountId && options.refId) {
|
|
123
|
+
var channel = "a-" + options.accountId + "$refid." + options.refId;
|
|
124
|
+
var exactMatch = [channel];
|
|
125
|
+
options.channels = {};
|
|
126
|
+
options.channels.exactMatch = exactMatch;
|
|
127
|
+
grantV2.call(this, options)
|
|
128
|
+
.then(function (res) {
|
|
129
|
+
dfd.resolve(res);
|
|
130
|
+
})
|
|
131
|
+
.catch(function(err) {
|
|
132
|
+
dfd.reject(err);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
err.message = err.description = "Required parameter ['accountId', 'refId'] " +
|
|
137
|
+
"not found in request options";
|
|
138
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
139
|
+
dfd.reject(err);
|
|
140
|
+
}
|
|
141
|
+
return dfd.promise;
|
|
165
142
|
}
|
|
166
143
|
|
|
167
144
|
/*options = {
|
|
168
145
|
accountId: <accountid>,
|
|
169
146
|
extUserId: <extUserId>, //mandatory
|
|
170
|
-
authKey: <authKey>
|
|
171
147
|
}*/
|
|
172
148
|
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
|
-
|
|
149
|
+
var err ={};
|
|
150
|
+
var dfd = q.defer(); // Initializing promise
|
|
151
|
+
|
|
152
|
+
if(options.accountId && options.extUserId) {
|
|
153
|
+
var channel = "a-" + options.accountId + "$u-" + options.extUserId;
|
|
154
|
+
var exactMatch = [channel];
|
|
155
|
+
options.channels = {};
|
|
156
|
+
options.channels.exactMatch = exactMatch;
|
|
157
|
+
grantV2.call(this, options)
|
|
158
|
+
.then(function (res) {
|
|
159
|
+
dfd.resolve(res);
|
|
160
|
+
})
|
|
161
|
+
.catch(function(err) {
|
|
162
|
+
dfd.reject(err);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
|
|
167
|
+
"not found in request options";
|
|
168
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
169
|
+
dfd.reject(err);
|
|
170
|
+
}
|
|
171
|
+
return dfd.promise;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* This function provides grant token on given channels
|
|
176
|
+
* @param { channels: { exactMatch: [], patterns: [] } } options
|
|
177
|
+
* @returns { token, publishKey, subscribeKey }
|
|
178
|
+
*/
|
|
179
|
+
function grantV2(options) {
|
|
180
|
+
var self = this, err = {};
|
|
181
|
+
var dfd = q.defer();
|
|
182
|
+
var body = { channels: {} };
|
|
183
|
+
if(!options.channels) {
|
|
184
|
+
err.message = err.description = "channels not given in input body.";
|
|
185
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
186
|
+
dfd.reject(err);
|
|
204
187
|
return dfd.promise;
|
|
188
|
+
}
|
|
189
|
+
body.channels = options.channels;
|
|
190
|
+
// Passed all validations, Construct API url
|
|
191
|
+
var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantV2;
|
|
192
|
+
// Setup request with URL and Params
|
|
193
|
+
var requestAPI = request.post(url)
|
|
194
|
+
.set('Content-Type', 'application/json')
|
|
195
|
+
.set('Accept', 'application/json');
|
|
196
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
197
|
+
|
|
198
|
+
requestAPI.send(body);
|
|
199
|
+
requestAPI.end(function(err, response) {
|
|
200
|
+
if(err) {
|
|
201
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
202
|
+
dfd.reject(err);
|
|
203
|
+
}
|
|
204
|
+
else { dfd.resolve(response.body); }
|
|
205
|
+
});
|
|
206
|
+
return dfd.promise;
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
/**
|
|
@@ -36,6 +36,7 @@ module.exports = function () {
|
|
|
36
36
|
//Returning the adaptor (Plain Javascript object)
|
|
37
37
|
return {
|
|
38
38
|
"on": function (channelObj, handler) {
|
|
39
|
+
console.log("0a781d69 PARAMS OF .on FUNCTION: ", JSON.stringify(channelObj, null, 2));
|
|
39
40
|
var pubNubChannel;
|
|
40
41
|
var channelContext = [];
|
|
41
42
|
|
|
@@ -57,6 +58,7 @@ module.exports = function () {
|
|
|
57
58
|
status: 'pending'
|
|
58
59
|
};
|
|
59
60
|
_eventEmitter.on(pubNubChannel, handler);
|
|
61
|
+
console.log("0a781d69 GOING TO SUBSCRIBE ON PUBNUB CHANNEL: ", pubNubChannel);
|
|
60
62
|
_subscribeToPubNubChannels(pubNubChannel);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -77,6 +79,7 @@ module.exports = function () {
|
|
|
77
79
|
|
|
78
80
|
var _translatePubnubStatus = function(status, options) {
|
|
79
81
|
var channels = [], error, successObj;
|
|
82
|
+
console.log('0a781d69 PUBNUB STATUS: ', JSON.stringify(status, null, 4));
|
|
80
83
|
switch (status.category) {
|
|
81
84
|
case "PNConnectedCategory":
|
|
82
85
|
if(status.operation === "PNSubscribeOperation") {
|
|
@@ -104,8 +107,10 @@ module.exports = function () {
|
|
|
104
107
|
break;
|
|
105
108
|
case "PNAccessDeniedCategory":
|
|
106
109
|
if(status.operation === "PNSubscribeOperation") {
|
|
110
|
+
var errorText = status.errorData.response && status.errorData.response.text;
|
|
111
|
+
var errorJSON = errorText ? JSON.parse(errorText) : undefined;
|
|
107
112
|
var errorData = {
|
|
108
|
-
payload:
|
|
113
|
+
payload: errorJSON && errorJSON.payload || status.errorData.payload,
|
|
109
114
|
message: 'Forbidden: Subscription failed.',
|
|
110
115
|
errorDetails: {
|
|
111
116
|
operation: status.operation,
|
|
@@ -208,10 +213,17 @@ module.exports = function () {
|
|
|
208
213
|
var pubnubConfig = userOptions.pubnub;
|
|
209
214
|
pubnubConfig.uuid = userOptions.userid;
|
|
210
215
|
var accountId = userOptions.accountid;
|
|
216
|
+
var token = userOptions.token;
|
|
211
217
|
|
|
212
218
|
if (!_pubnubClient && pubnubConfig) {
|
|
213
|
-
|
|
214
|
-
|
|
219
|
+
try {
|
|
220
|
+
_pubnubClient = new pubNub(pubnubConfig); //Connect with PubNub SDK
|
|
221
|
+
_pubnubClient.setToken(token);
|
|
222
|
+
setTimeout(processSetup, 1000);
|
|
223
|
+
processSetup();
|
|
224
|
+
} catch(err) {
|
|
225
|
+
console.error('0a781d69 ERROR WHILE CONFIGURING PUBNUB: ', JSON.stringify(err, null, 2));
|
|
226
|
+
}
|
|
215
227
|
} else {
|
|
216
228
|
return new Error('Already Initialized');
|
|
217
229
|
}
|