comprodls-sdk 2.123.2-security → 2.123.4-oidc-poc.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/.eslintrc +28 -28
- package/.github/workflows/npm-publish.yml +76 -0
- package/README.md +235 -235
- package/dist/comprodls-sdk.js +13543 -13543
- package/docs/npm-oidc-publishing-runbook.md +229 -0
- package/lib/comprodls.js +132 -132
- package/lib/config/index.js +356 -356
- package/lib/helpers/index.js +31 -31
- package/lib/helpers/lib/api/converter.js +129 -129
- package/lib/helpers/lib/api/index.js +46 -46
- package/lib/helpers/lib/errors.js +122 -122
- package/lib/helpers/lib/requestLayer.js +154 -154
- package/lib/helpers/lib/validator.js +192 -192
- package/lib/open_access/index.js +116 -116
- package/lib/services/analytics/index.js +1365 -1365
- package/lib/services/attempts/index.js +389 -389
- package/lib/services/auth/index.js +3708 -3708
- package/lib/services/authextn/index.js +1032 -1032
- package/lib/services/datasyncmanager/index.js +275 -275
- package/lib/services/drive/index.js +270 -270
- package/lib/services/integrations/index.js +525 -525
- package/lib/services/invitations/index.js +282 -282
- package/lib/services/product/index.js +343 -343
- package/lib/services/pub/index.js +530 -530
- package/lib/services/pushX/index.js +251 -251
- package/lib/services/pushX/pubnubClientWrapper.js +438 -438
- package/lib/services/rules/index.js +416 -416
- package/lib/services/spaces/index.js +999 -999
- package/lib/services/spacesextn/index.js +131 -131
- package/lib/services/superuser/index.js +160 -160
- package/lib/services/taxonomy/index.js +405 -405
- package/lib/services/workflows/index.js +406 -406
- package/lib/services/xapi/index.js +114 -114
- package/lib/token/index.js +120 -120
- package/lib/token/validations.js +85 -85
- package/package.json +5 -1
|
@@ -1,251 +1,251 @@
|
|
|
1
|
-
/*************************************************************************
|
|
2
|
-
*
|
|
3
|
-
* COMPRO CONFIDENTIAL
|
|
4
|
-
* __________________
|
|
5
|
-
*
|
|
6
|
-
* [2015] - [2020] Compro Technologies Private Limited
|
|
7
|
-
* All Rights Reserved.
|
|
8
|
-
*
|
|
9
|
-
* NOTICE: All information contained herein is, and remains
|
|
10
|
-
* the property of Compro Technologies Private Limited. The
|
|
11
|
-
* intellectual and technical concepts contained herein are
|
|
12
|
-
* proprietary to Compro Technologies Private Limited and may
|
|
13
|
-
* be covered by U.S. and Foreign Patents, patents in process,
|
|
14
|
-
* and are protected by trade secret or copyright law.
|
|
15
|
-
*
|
|
16
|
-
* Dissemination of this information or reproduction of this material
|
|
17
|
-
* is strictly forbidden unless prior written permission is obtained
|
|
18
|
-
* from Compro Technologies Pvt. Ltd..
|
|
19
|
-
***************************************************************************/
|
|
20
|
-
|
|
21
|
-
/***********************************************************
|
|
22
|
-
* comproDLS SDK PUSHX Adaptor
|
|
23
|
-
* Functions for calling PUSHX.
|
|
24
|
-
************************************************************/
|
|
25
|
-
|
|
26
|
-
var q = require('q');
|
|
27
|
-
var request = require('superagent');
|
|
28
|
-
var Agent = require('agentkeepalive');
|
|
29
|
-
|
|
30
|
-
var helpers = require('../../helpers');
|
|
31
|
-
var pubnubClientWrapper = require('./pubnubClientWrapper');
|
|
32
|
-
var DLSError = helpers.errors.DLSError;
|
|
33
|
-
|
|
34
|
-
module.exports = pushX;
|
|
35
|
-
|
|
36
|
-
var keepaliveAgent = new Agent({
|
|
37
|
-
timeout: 60000,
|
|
38
|
-
freeSocketTimeout: 30000
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
function pushX() {
|
|
42
|
-
var _pubnubClientWrapper = pubnubClientWrapper();
|
|
43
|
-
return {
|
|
44
|
-
connect: _connect.bind(this, _pubnubClientWrapper),
|
|
45
|
-
cleanup: _cleanup.bind(this, _pubnubClientWrapper),
|
|
46
|
-
grantByUserOrgId: grantByUserOrgId.bind(this),
|
|
47
|
-
grantByAccountId: grantByAccountId.bind(this),
|
|
48
|
-
grantByAccountIdOnExtUserId: grantByAccountIdOnExtUserId.bind(this),
|
|
49
|
-
grantV2: grantV2.bind(this),
|
|
50
|
-
getPushedEvents: getPushedEvents.bind(this)
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/*********************************
|
|
55
|
-
* Public Function definitions
|
|
56
|
-
**********************************/
|
|
57
|
-
|
|
58
|
-
function _connect(pubnubCW, options) {
|
|
59
|
-
var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
|
|
60
|
-
if (bpubnubV7 && !options.userid) {
|
|
61
|
-
var err = {};
|
|
62
|
-
err.message = err.description = 'Mandatory parameter userid not found in request options.';
|
|
63
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.PUSHX_ERROR, err);
|
|
64
|
-
throw err;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Adding SSL flag
|
|
68
|
-
return pubnubCW.setup({
|
|
69
|
-
'userid': options.userid,
|
|
70
|
-
'accountid': options.accountid,
|
|
71
|
-
'token': options.token,
|
|
72
|
-
'pubnub': {
|
|
73
|
-
'publishKey': options.publishKey,
|
|
74
|
-
'subscribeKey': options.subscribeKey,
|
|
75
|
-
'ssl': true,
|
|
76
|
-
'suppressLeaveEvents': true
|
|
77
|
-
},
|
|
78
|
-
'pollingEndpoint': options.pollingEndpoint,
|
|
79
|
-
'pollingIterations': options.pollingIterations || 10, // Default polling iterations is 10
|
|
80
|
-
'pollingInterval': options.pollingInterval, // Default polling interval is exponential backoff
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Wiki Link for SDK params
|
|
86
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#cleanup
|
|
87
|
-
*/
|
|
88
|
-
function _cleanup(pubnubCW) { pubnubCW.cleanup(); }
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Wiki Link for SDK params
|
|
92
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-user--org-level-grants
|
|
93
|
-
*/
|
|
94
|
-
function grantByUserOrgId(options) {
|
|
95
|
-
var dfd = q.defer(); // Initializing promise
|
|
96
|
-
var allowedChannels = ['jobs', 'systemevents'];
|
|
97
|
-
var baseChannelName = "o-" + this.orgId + "\\$u-" + this.token.access_token + "\\$";
|
|
98
|
-
var patterns = [];
|
|
99
|
-
for(var i in allowedChannels) {
|
|
100
|
-
var channelName = baseChannelName + allowedChannels[i] + "\\..*";
|
|
101
|
-
patterns.push(channelName);
|
|
102
|
-
}
|
|
103
|
-
options.channels = {};
|
|
104
|
-
options.channels.patterns = patterns;
|
|
105
|
-
grantV2.call(this, options)
|
|
106
|
-
.then(function (res) {
|
|
107
|
-
dfd.resolve(res);
|
|
108
|
-
})
|
|
109
|
-
.catch(function(err) {
|
|
110
|
-
dfd.reject(err);
|
|
111
|
-
});
|
|
112
|
-
return dfd.promise;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Wiki Link for SDK params
|
|
117
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-account-level-grants
|
|
118
|
-
*/
|
|
119
|
-
function grantByAccountId(options) {
|
|
120
|
-
var err ={};
|
|
121
|
-
var dfd = q.defer(); // Initializing promise
|
|
122
|
-
|
|
123
|
-
if(options.accountId && options.refId) {
|
|
124
|
-
var channel = "a-" + options.accountId + "$refid." + options.refId;
|
|
125
|
-
var exactMatch = [channel];
|
|
126
|
-
options.channels = {};
|
|
127
|
-
options.channels.exactMatch = exactMatch;
|
|
128
|
-
grantV2.call(this, options)
|
|
129
|
-
.then(function (res) {
|
|
130
|
-
dfd.resolve(res);
|
|
131
|
-
})
|
|
132
|
-
.catch(function(err) {
|
|
133
|
-
dfd.reject(err);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
err.message = err.description = "Required parameter ['accountId', 'refId'] " +
|
|
138
|
-
"not found in request options";
|
|
139
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
140
|
-
dfd.reject(err);
|
|
141
|
-
}
|
|
142
|
-
return dfd.promise;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Wiki Link for SDK params
|
|
147
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-account-level-grants-on-extuserid
|
|
148
|
-
*/
|
|
149
|
-
function grantByAccountIdOnExtUserId(options) {
|
|
150
|
-
var err ={};
|
|
151
|
-
var dfd = q.defer(); // Initializing promise
|
|
152
|
-
|
|
153
|
-
if(options.accountId && options.extUserId) {
|
|
154
|
-
var channel = "a-" + options.accountId + "$u-" + options.extUserId;
|
|
155
|
-
var exactMatch = [channel];
|
|
156
|
-
options.channels = {};
|
|
157
|
-
options.channels.exactMatch = exactMatch;
|
|
158
|
-
grantV2.call(this, options)
|
|
159
|
-
.then(function (res) {
|
|
160
|
-
dfd.resolve(res);
|
|
161
|
-
})
|
|
162
|
-
.catch(function(err) {
|
|
163
|
-
dfd.reject(err);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
|
|
168
|
-
"not found in request options";
|
|
169
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
170
|
-
dfd.reject(err);
|
|
171
|
-
}
|
|
172
|
-
return dfd.promise;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* This function provides grant token on given channels
|
|
177
|
-
* Wiki Link for SDK params
|
|
178
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-grant-token-for-the-access-manager-v3
|
|
179
|
-
*/
|
|
180
|
-
function grantV2(options) {
|
|
181
|
-
var self = this, err = {};
|
|
182
|
-
var dfd = q.defer();
|
|
183
|
-
var body = { channels: {} };
|
|
184
|
-
if(!options.channels) {
|
|
185
|
-
err.message = err.description = "channels not given in input body.";
|
|
186
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
187
|
-
dfd.reject(err);
|
|
188
|
-
return dfd.promise;
|
|
189
|
-
}
|
|
190
|
-
body.channels = options.channels;
|
|
191
|
-
// Passed all validations, Construct API url
|
|
192
|
-
var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantV2;
|
|
193
|
-
// Setup request with URL and Params
|
|
194
|
-
var requestAPI = request.post(url)
|
|
195
|
-
.set('Content-Type', 'application/json')
|
|
196
|
-
.set('Accept', 'application/json');
|
|
197
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
198
|
-
|
|
199
|
-
requestAPI.send(body);
|
|
200
|
-
requestAPI.end(function(err, response) {
|
|
201
|
-
if(err) {
|
|
202
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
203
|
-
dfd.reject(err);
|
|
204
|
-
}
|
|
205
|
-
else { dfd.resolve(response.body); }
|
|
206
|
-
});
|
|
207
|
-
return dfd.promise;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Wiki Link for SDK params
|
|
212
|
-
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#getpushedeventsparams
|
|
213
|
-
*/
|
|
214
|
-
function getPushedEvents(options) {
|
|
215
|
-
var self = this;
|
|
216
|
-
var dfd = q.defer(); // Initializing promise
|
|
217
|
-
var accountid = options.accountid,
|
|
218
|
-
channelname = options.channelname,
|
|
219
|
-
starttime = options.starttime,
|
|
220
|
-
endtime = options.endtime;
|
|
221
|
-
|
|
222
|
-
if (accountid && channelname && starttime && endtime) {
|
|
223
|
-
// Passed all validations, Construct API url
|
|
224
|
-
var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.getPushedEvents;
|
|
225
|
-
url = helpers.api.constructAPIUrl(url, { accountId: accountid });
|
|
226
|
-
|
|
227
|
-
// Setup request with URL and Params
|
|
228
|
-
var params = {channelname: channelname, starttime: starttime, endtime: endtime};
|
|
229
|
-
var requestAPI = request.get(url).query(params);
|
|
230
|
-
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
231
|
-
|
|
232
|
-
requestAPI
|
|
233
|
-
.agent(keepaliveAgent)
|
|
234
|
-
.end(function(error, response) {
|
|
235
|
-
if (error) {
|
|
236
|
-
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
237
|
-
dfd.reject(error);
|
|
238
|
-
} else {
|
|
239
|
-
dfd.resolve(response.body);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
var err = {};
|
|
245
|
-
err.message = err.description = 'Mandatory parameters [accountId, channelname,' +
|
|
246
|
-
' starttime, endtime] not found in request options';
|
|
247
|
-
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
248
|
-
dfd.reject(err);
|
|
249
|
-
}
|
|
250
|
-
return dfd.promise;
|
|
251
|
-
}
|
|
1
|
+
/*************************************************************************
|
|
2
|
+
*
|
|
3
|
+
* COMPRO CONFIDENTIAL
|
|
4
|
+
* __________________
|
|
5
|
+
*
|
|
6
|
+
* [2015] - [2020] Compro Technologies Private Limited
|
|
7
|
+
* All Rights Reserved.
|
|
8
|
+
*
|
|
9
|
+
* NOTICE: All information contained herein is, and remains
|
|
10
|
+
* the property of Compro Technologies Private Limited. The
|
|
11
|
+
* intellectual and technical concepts contained herein are
|
|
12
|
+
* proprietary to Compro Technologies Private Limited and may
|
|
13
|
+
* be covered by U.S. and Foreign Patents, patents in process,
|
|
14
|
+
* and are protected by trade secret or copyright law.
|
|
15
|
+
*
|
|
16
|
+
* Dissemination of this information or reproduction of this material
|
|
17
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
18
|
+
* from Compro Technologies Pvt. Ltd..
|
|
19
|
+
***************************************************************************/
|
|
20
|
+
|
|
21
|
+
/***********************************************************
|
|
22
|
+
* comproDLS SDK PUSHX Adaptor
|
|
23
|
+
* Functions for calling PUSHX.
|
|
24
|
+
************************************************************/
|
|
25
|
+
|
|
26
|
+
var q = require('q');
|
|
27
|
+
var request = require('superagent');
|
|
28
|
+
var Agent = require('agentkeepalive');
|
|
29
|
+
|
|
30
|
+
var helpers = require('../../helpers');
|
|
31
|
+
var pubnubClientWrapper = require('./pubnubClientWrapper');
|
|
32
|
+
var DLSError = helpers.errors.DLSError;
|
|
33
|
+
|
|
34
|
+
module.exports = pushX;
|
|
35
|
+
|
|
36
|
+
var keepaliveAgent = new Agent({
|
|
37
|
+
timeout: 60000,
|
|
38
|
+
freeSocketTimeout: 30000
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function pushX() {
|
|
42
|
+
var _pubnubClientWrapper = pubnubClientWrapper();
|
|
43
|
+
return {
|
|
44
|
+
connect: _connect.bind(this, _pubnubClientWrapper),
|
|
45
|
+
cleanup: _cleanup.bind(this, _pubnubClientWrapper),
|
|
46
|
+
grantByUserOrgId: grantByUserOrgId.bind(this),
|
|
47
|
+
grantByAccountId: grantByAccountId.bind(this),
|
|
48
|
+
grantByAccountIdOnExtUserId: grantByAccountIdOnExtUserId.bind(this),
|
|
49
|
+
grantV2: grantV2.bind(this),
|
|
50
|
+
getPushedEvents: getPushedEvents.bind(this)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/*********************************
|
|
55
|
+
* Public Function definitions
|
|
56
|
+
**********************************/
|
|
57
|
+
|
|
58
|
+
function _connect(pubnubCW, options) {
|
|
59
|
+
var bpubnubV7 = true; // If pubnub v7 or higher in package.json, set it true
|
|
60
|
+
if (bpubnubV7 && !options.userid) {
|
|
61
|
+
var err = {};
|
|
62
|
+
err.message = err.description = 'Mandatory parameter userid not found in request options.';
|
|
63
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.PUSHX_ERROR, err);
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Adding SSL flag
|
|
68
|
+
return pubnubCW.setup({
|
|
69
|
+
'userid': options.userid,
|
|
70
|
+
'accountid': options.accountid,
|
|
71
|
+
'token': options.token,
|
|
72
|
+
'pubnub': {
|
|
73
|
+
'publishKey': options.publishKey,
|
|
74
|
+
'subscribeKey': options.subscribeKey,
|
|
75
|
+
'ssl': true,
|
|
76
|
+
'suppressLeaveEvents': true
|
|
77
|
+
},
|
|
78
|
+
'pollingEndpoint': options.pollingEndpoint,
|
|
79
|
+
'pollingIterations': options.pollingIterations || 10, // Default polling iterations is 10
|
|
80
|
+
'pollingInterval': options.pollingInterval, // Default polling interval is exponential backoff
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Wiki Link for SDK params
|
|
86
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#cleanup
|
|
87
|
+
*/
|
|
88
|
+
function _cleanup(pubnubCW) { pubnubCW.cleanup(); }
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Wiki Link for SDK params
|
|
92
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-user--org-level-grants
|
|
93
|
+
*/
|
|
94
|
+
function grantByUserOrgId(options) {
|
|
95
|
+
var dfd = q.defer(); // Initializing promise
|
|
96
|
+
var allowedChannels = ['jobs', 'systemevents'];
|
|
97
|
+
var baseChannelName = "o-" + this.orgId + "\\$u-" + this.token.access_token + "\\$";
|
|
98
|
+
var patterns = [];
|
|
99
|
+
for(var i in allowedChannels) {
|
|
100
|
+
var channelName = baseChannelName + allowedChannels[i] + "\\..*";
|
|
101
|
+
patterns.push(channelName);
|
|
102
|
+
}
|
|
103
|
+
options.channels = {};
|
|
104
|
+
options.channels.patterns = patterns;
|
|
105
|
+
grantV2.call(this, options)
|
|
106
|
+
.then(function (res) {
|
|
107
|
+
dfd.resolve(res);
|
|
108
|
+
})
|
|
109
|
+
.catch(function(err) {
|
|
110
|
+
dfd.reject(err);
|
|
111
|
+
});
|
|
112
|
+
return dfd.promise;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Wiki Link for SDK params
|
|
117
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-account-level-grants
|
|
118
|
+
*/
|
|
119
|
+
function grantByAccountId(options) {
|
|
120
|
+
var err ={};
|
|
121
|
+
var dfd = q.defer(); // Initializing promise
|
|
122
|
+
|
|
123
|
+
if(options.accountId && options.refId) {
|
|
124
|
+
var channel = "a-" + options.accountId + "$refid." + options.refId;
|
|
125
|
+
var exactMatch = [channel];
|
|
126
|
+
options.channels = {};
|
|
127
|
+
options.channels.exactMatch = exactMatch;
|
|
128
|
+
grantV2.call(this, options)
|
|
129
|
+
.then(function (res) {
|
|
130
|
+
dfd.resolve(res);
|
|
131
|
+
})
|
|
132
|
+
.catch(function(err) {
|
|
133
|
+
dfd.reject(err);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
err.message = err.description = "Required parameter ['accountId', 'refId'] " +
|
|
138
|
+
"not found in request options";
|
|
139
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
140
|
+
dfd.reject(err);
|
|
141
|
+
}
|
|
142
|
+
return dfd.promise;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Wiki Link for SDK params
|
|
147
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-account-level-grants-on-extuserid
|
|
148
|
+
*/
|
|
149
|
+
function grantByAccountIdOnExtUserId(options) {
|
|
150
|
+
var err ={};
|
|
151
|
+
var dfd = q.defer(); // Initializing promise
|
|
152
|
+
|
|
153
|
+
if(options.accountId && options.extUserId) {
|
|
154
|
+
var channel = "a-" + options.accountId + "$u-" + options.extUserId;
|
|
155
|
+
var exactMatch = [channel];
|
|
156
|
+
options.channels = {};
|
|
157
|
+
options.channels.exactMatch = exactMatch;
|
|
158
|
+
grantV2.call(this, options)
|
|
159
|
+
.then(function (res) {
|
|
160
|
+
dfd.resolve(res);
|
|
161
|
+
})
|
|
162
|
+
.catch(function(err) {
|
|
163
|
+
dfd.reject(err);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
err.message = err.description = "Required parameter ['accountId', 'extUserId'] " +
|
|
168
|
+
"not found in request options";
|
|
169
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
170
|
+
dfd.reject(err);
|
|
171
|
+
}
|
|
172
|
+
return dfd.promise;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* This function provides grant token on given channels
|
|
177
|
+
* Wiki Link for SDK params
|
|
178
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#get-grant-token-for-the-access-manager-v3
|
|
179
|
+
*/
|
|
180
|
+
function grantV2(options) {
|
|
181
|
+
var self = this, err = {};
|
|
182
|
+
var dfd = q.defer();
|
|
183
|
+
var body = { channels: {} };
|
|
184
|
+
if(!options.channels) {
|
|
185
|
+
err.message = err.description = "channels not given in input body.";
|
|
186
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
187
|
+
dfd.reject(err);
|
|
188
|
+
return dfd.promise;
|
|
189
|
+
}
|
|
190
|
+
body.channels = options.channels;
|
|
191
|
+
// Passed all validations, Construct API url
|
|
192
|
+
var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.grantV2;
|
|
193
|
+
// Setup request with URL and Params
|
|
194
|
+
var requestAPI = request.post(url)
|
|
195
|
+
.set('Content-Type', 'application/json')
|
|
196
|
+
.set('Accept', 'application/json');
|
|
197
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
198
|
+
|
|
199
|
+
requestAPI.send(body);
|
|
200
|
+
requestAPI.end(function(err, response) {
|
|
201
|
+
if(err) {
|
|
202
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
|
|
203
|
+
dfd.reject(err);
|
|
204
|
+
}
|
|
205
|
+
else { dfd.resolve(response.body); }
|
|
206
|
+
});
|
|
207
|
+
return dfd.promise;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Wiki Link for SDK params
|
|
212
|
+
* https://github.com/comprodls/comprodls-sdk-js/wiki/19_PUSHX-Adapter#getpushedeventsparams
|
|
213
|
+
*/
|
|
214
|
+
function getPushedEvents(options) {
|
|
215
|
+
var self = this;
|
|
216
|
+
var dfd = q.defer(); // Initializing promise
|
|
217
|
+
var accountid = options.accountid,
|
|
218
|
+
channelname = options.channelname,
|
|
219
|
+
starttime = options.starttime,
|
|
220
|
+
endtime = options.endtime;
|
|
221
|
+
|
|
222
|
+
if (accountid && channelname && starttime && endtime) {
|
|
223
|
+
// Passed all validations, Construct API url
|
|
224
|
+
var url = self.config.DEFAULT_HOSTS.PUSHX + self.config.PUSHX_API_URLS.getPushedEvents;
|
|
225
|
+
url = helpers.api.constructAPIUrl(url, { accountId: accountid });
|
|
226
|
+
|
|
227
|
+
// Setup request with URL and Params
|
|
228
|
+
var params = {channelname: channelname, starttime: starttime, endtime: endtime};
|
|
229
|
+
var requestAPI = request.get(url).query(params);
|
|
230
|
+
if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
|
|
231
|
+
|
|
232
|
+
requestAPI
|
|
233
|
+
.agent(keepaliveAgent)
|
|
234
|
+
.end(function(error, response) {
|
|
235
|
+
if (error) {
|
|
236
|
+
error = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
|
|
237
|
+
dfd.reject(error);
|
|
238
|
+
} else {
|
|
239
|
+
dfd.resolve(response.body);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
var err = {};
|
|
245
|
+
err.message = err.description = 'Mandatory parameters [accountId, channelname,' +
|
|
246
|
+
' starttime, endtime] not found in request options';
|
|
247
|
+
err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
|
|
248
|
+
dfd.reject(err);
|
|
249
|
+
}
|
|
250
|
+
return dfd.promise;
|
|
251
|
+
}
|