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.
Files changed (36) hide show
  1. package/.eslintrc +28 -28
  2. package/.github/workflows/npm-publish.yml +76 -0
  3. package/README.md +235 -235
  4. package/dist/comprodls-sdk.js +13543 -13543
  5. package/docs/npm-oidc-publishing-runbook.md +229 -0
  6. package/lib/comprodls.js +132 -132
  7. package/lib/config/index.js +356 -356
  8. package/lib/helpers/index.js +31 -31
  9. package/lib/helpers/lib/api/converter.js +129 -129
  10. package/lib/helpers/lib/api/index.js +46 -46
  11. package/lib/helpers/lib/errors.js +122 -122
  12. package/lib/helpers/lib/requestLayer.js +154 -154
  13. package/lib/helpers/lib/validator.js +192 -192
  14. package/lib/open_access/index.js +116 -116
  15. package/lib/services/analytics/index.js +1365 -1365
  16. package/lib/services/attempts/index.js +389 -389
  17. package/lib/services/auth/index.js +3708 -3708
  18. package/lib/services/authextn/index.js +1032 -1032
  19. package/lib/services/datasyncmanager/index.js +275 -275
  20. package/lib/services/drive/index.js +270 -270
  21. package/lib/services/integrations/index.js +525 -525
  22. package/lib/services/invitations/index.js +282 -282
  23. package/lib/services/product/index.js +343 -343
  24. package/lib/services/pub/index.js +530 -530
  25. package/lib/services/pushX/index.js +251 -251
  26. package/lib/services/pushX/pubnubClientWrapper.js +438 -438
  27. package/lib/services/rules/index.js +416 -416
  28. package/lib/services/spaces/index.js +999 -999
  29. package/lib/services/spacesextn/index.js +131 -131
  30. package/lib/services/superuser/index.js +160 -160
  31. package/lib/services/taxonomy/index.js +405 -405
  32. package/lib/services/workflows/index.js +406 -406
  33. package/lib/services/xapi/index.js +114 -114
  34. package/lib/token/index.js +120 -120
  35. package/lib/token/validations.js +85 -85
  36. package/package.json +5 -1
@@ -1,416 +1,416 @@
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 Rules API Adaptor
23
- * Functions for calling Rules API.
24
- ************************************************************/
25
-
26
- var q = require('q');
27
- var request = require('superagent');
28
- var helpers = require('../../helpers');
29
- var Agent = require('agentkeepalive');
30
-
31
- var DLSError = helpers.errors.DLSError;
32
-
33
- module.exports = rules;
34
-
35
- var keepaliveAgent = new Agent({
36
- timeout: 60000,
37
- freeSocketTimeout: 30000
38
- });
39
-
40
- //Rules Adaptor Contsructor
41
- function rules() {
42
- return {
43
- getRules: getRules.bind(this),
44
- getParticularRule: getParticularRule.bind(this),
45
- getUserRule: getUserRule.bind(this),
46
- updateRuleDisplay: updateRuleDisplay.bind(this),
47
- createRule: createRule.bind(this),
48
- updateRule: updateRule.bind(this),
49
- deleteRule: deleteRule.bind(this)
50
- };
51
- }
52
-
53
- /*********************************
54
- * Public Function definitions
55
- **********************************/
56
-
57
- /**
58
- * Wiki Link for SDK params
59
- * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#getrulesparams
60
- */
61
- function getRules(options) {
62
- var self = this;
63
-
64
- //Initializing promise
65
- var dfd = q.defer();
66
-
67
- //Validations
68
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
69
- if (err) {
70
- dfd.reject(err);
71
- } else {
72
- if (options && options.context && options.ruleType) {
73
- //Passed all validations, Contruct API url
74
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.rules;
75
- url = helpers.api.constructAPIUrl(url, {
76
- orgId: self.orgId,
77
- context: encodeURIComponent(options.context),
78
- ruleType: options.ruleType
79
- });
80
-
81
- //Setup request with URL and Params
82
- var queryParam = { cursor: options.cursor };
83
-
84
- var requestAPI = request.get(url)
85
- .set('Content-Type', 'application/json')
86
- .set('Accept', 'application/json')
87
- .query(queryParam);
88
-
89
- if (self.traceid) {
90
- requestAPI.set('X-Amzn-Trace-Id', self.traceid);
91
- }
92
-
93
- //Setup token in Authorization header
94
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
95
-
96
- requestAPI.end(function (err, response) {
97
- if (err) {
98
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
99
- dfd.reject(err);
100
- } else {
101
- dfd.resolve(response.body);
102
- }
103
- });
104
- } else {
105
- err = {};
106
- err.message = err.description = 'context or ruleType not found in request options.';
107
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
108
- dfd.reject(err);
109
- }
110
- }
111
- return dfd.promise;
112
- }
113
-
114
- /**
115
- * Wiki Link for SDK params
116
- * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#getparticularruleparams
117
- */
118
- function getParticularRule(options) {
119
- var self = this;
120
-
121
- //Initializing promise
122
- var dfd = q.defer();
123
-
124
- //Validations
125
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
126
- if (err) {
127
- dfd.reject(err);
128
- } else {
129
- if (options && options.context && options.ruleType && options.ruleId) {
130
- //Passed all validations, Contruct API url
131
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
132
- url = helpers.api.constructAPIUrl(url, {
133
- orgId: self.orgId,
134
- context: encodeURIComponent(options.context),
135
- ruleType: options.ruleType,
136
- ruleId: options.ruleId
137
- });
138
-
139
- //Setup request with URL and Params
140
- var requestAPI = request.get(url);
141
-
142
- if (self.traceid) {
143
- requestAPI.set('X-Amzn-Trace-Id', self.traceid);
144
- }
145
-
146
- //Setup token in Authorization header
147
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
148
-
149
- requestAPI.end(function (err, response) {
150
- if (err) {
151
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
152
- dfd.reject(err);
153
- } else {
154
- dfd.resolve(response.body);
155
- }
156
- });
157
- } else {
158
- err = {};
159
- err.message = err.description = 'context or ruleType or ruleId not found' +
160
- ' in request options.';
161
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
162
- dfd.reject(err);
163
- }
164
- }
165
- return dfd.promise;
166
- }
167
-
168
- /**
169
- * Wiki Link for SDK params
170
- * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#getuserruleparams
171
- */
172
- function getUserRule(options) {
173
- var self = this;
174
-
175
- //Initializing promise
176
- var dfd = q.defer();
177
-
178
- if (options && options.orgId && options.context && options.ruleType && options.userId) {
179
- //Passed all validations, Contruct API url
180
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.getUserRule;
181
- url = helpers.api.constructAPIUrl(url, {
182
- orgId: self.orgId,
183
- context: encodeURIComponent(options.context),
184
- ruleType: options.ruleType,
185
- userId: options.userId
186
- });
187
-
188
- var requestAPI = request.get(url)
189
- .set('Content-Type', 'application/json')
190
- .set('Accept', 'application/json');
191
-
192
- if (self.traceid) {
193
- requestAPI.set('X-Amzn-Trace-Id', self.traceid);
194
- }
195
-
196
- //Setup token in Authorization header
197
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
198
-
199
- requestAPI
200
- .agent(keepaliveAgent)
201
- .end(function (err, response) {
202
- if (err) {
203
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
204
- dfd.reject(err);
205
- } else {
206
- dfd.resolve(response.body);
207
- }
208
- });
209
- } else {
210
- var err = {};
211
- err.message = err.description = 'Mandatory params - orgId or context or ruleType or userId ' +
212
- 'not found in request options.';
213
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
214
- dfd.reject(err);
215
- }
216
-
217
- return dfd.promise;
218
- }
219
-
220
- /**
221
- * Wiki Link for SDK params
222
- * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#updateruledisplayparams
223
- */
224
- function updateRuleDisplay(options) {
225
- var self = this;
226
- // Initializing promise
227
- var dfd = q.defer();
228
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
229
- if (err) { dfd.reject(err); }
230
- else {
231
- if (options && options.context && options.ruleType && options.ruleId &&
232
- options.body && options.body.rule_display) {
233
- // Passed all validations, Contruct API url
234
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.updateRuleDisplay;
235
- url = helpers.api.constructAPIUrl(url, {
236
- orgId: self.orgId,
237
- context: encodeURIComponent(options.context),
238
- ruleType: options.ruleType,
239
- ruleId: options.ruleId
240
- });
241
-
242
- // Setup request with URL and Params
243
- var requestAPI = request.put(url)
244
- .set('Content-Type', 'application/json')
245
- .set('Accept', 'application/json')
246
- .send(options.body);
247
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
248
-
249
- //Setup token in Authorization header
250
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
251
-
252
- requestAPI.end(function (error, response) {
253
- if (error) {
254
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
255
- dfd.reject(err);
256
- }
257
- else { dfd.resolve(response.body); }
258
- });
259
- } else {
260
- err = {};
261
- err.message = err.description = 'Mandatory params - context or ruleType or ruleId ' +
262
- 'or body.rule_display not found in request options.';
263
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
264
- dfd.reject(err);
265
- }
266
- }
267
- return dfd.promise;
268
- }
269
-
270
- /**
271
- * Wiki Link for SDK params
272
- * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#createruleparams
273
- */
274
- function createRule(options) {
275
- var self = this;
276
- // Initializing promise
277
- var dfd = q.defer();
278
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
279
- if (err) { dfd.reject(err); }
280
- else {
281
- if (options && options.context && options.ruleType && options.body) {
282
- // Passed all validations, Contruct API url
283
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.rules;
284
- url = helpers.api.constructAPIUrl(url, {
285
- orgId: self.orgId,
286
- context: encodeURIComponent(options.context),
287
- ruleType: options.ruleType
288
- });
289
-
290
- // Setup request with URL and Params
291
- var requestAPI = request.post(url)
292
- .set('Content-Type', 'application/json')
293
- .set('Accept', 'application/json')
294
- .send(options.body);
295
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
296
-
297
- //Setup token in Authorization header
298
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
299
-
300
- requestAPI.end(function (error, response) {
301
- if (error) {
302
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
303
- dfd.reject(err);
304
- }
305
- else { dfd.resolve(response.body); }
306
- });
307
- } else {
308
- err = {};
309
- err.message = err.description = 'Mandatory params - context or ruleType or body' +
310
- ' not found in request options.';
311
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
312
- dfd.reject(err);
313
- }
314
- }
315
- return dfd.promise;
316
- }
317
-
318
- /**
319
- * Wiki Link for SDK params
320
- * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#updateruleparams
321
- */
322
- function updateRule(options) {
323
- var self = this;
324
- // Initializing promise
325
- var dfd = q.defer();
326
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
327
- if (err) { dfd.reject(err); }
328
- else {
329
- if (options && options.context && options.ruleType && options.ruleId && options.body) {
330
- // Passed all validations, Contruct API url
331
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
332
- url = helpers.api.constructAPIUrl(url, {
333
- orgId: self.orgId,
334
- context: encodeURIComponent(options.context),
335
- ruleType: options.ruleType,
336
- ruleId: options.ruleId
337
- });
338
-
339
- // Setup request with URL and Params
340
- var requestAPI = request.put(url)
341
- .set('Content-Type', 'application/json')
342
- .set('Accept', 'application/json')
343
- .send(options.body);
344
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
345
-
346
- //Setup token in Authorization header
347
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
348
-
349
- requestAPI.end(function (error, response) {
350
- if (error) {
351
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
352
- dfd.reject(err);
353
- }
354
- else { dfd.resolve(response.body); }
355
- });
356
- } else {
357
- err = {};
358
- err.message = err.description = 'Mandatory params - context or ruleType or ruleId or body ' +
359
- 'not found in request options.';
360
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
361
- dfd.reject(err);
362
- }
363
- }
364
- return dfd.promise;
365
- }
366
-
367
- /**
368
- * Wiki Link for SDK params
369
- * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#deleteruleparams
370
- */
371
- function deleteRule(options) {
372
- var self = this;
373
- // Initializing promise
374
- var dfd = q.defer();
375
-
376
- var err = helpers.validations.isAuthenticated(self.orgId, self.token);
377
- if (err) { dfd.reject(err); }
378
- else {
379
- if (options && options.context && options.ruleType && options.ruleId) {
380
- // Passed all validations, Contruct API url
381
- var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
382
- url = helpers.api.constructAPIUrl(url, {
383
- orgId: self.orgId,
384
- context: encodeURIComponent(options.context),
385
- ruleType: options.ruleType,
386
- ruleId: options.ruleId
387
- });
388
-
389
- // Setup request with URL and Params
390
- var requestAPI = request.delete(url);
391
-
392
- //Setup token in Authorization header
393
- requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
394
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
395
-
396
- requestAPI.end(function (error, response) {
397
- if (error) {
398
- err = {};
399
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
400
- dfd.reject(err);
401
- }
402
- else {
403
- dfd.resolve(response.body);
404
- }
405
- });
406
- }
407
- else {
408
- err = {};
409
- err.message = err.description = 'Mandatory params - context or ruleType or ruleId not found' +
410
- ' in request options.';
411
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
412
- dfd.reject(err);
413
- }
414
- }
415
- return dfd.promise;
416
- }
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 Rules API Adaptor
23
+ * Functions for calling Rules API.
24
+ ************************************************************/
25
+
26
+ var q = require('q');
27
+ var request = require('superagent');
28
+ var helpers = require('../../helpers');
29
+ var Agent = require('agentkeepalive');
30
+
31
+ var DLSError = helpers.errors.DLSError;
32
+
33
+ module.exports = rules;
34
+
35
+ var keepaliveAgent = new Agent({
36
+ timeout: 60000,
37
+ freeSocketTimeout: 30000
38
+ });
39
+
40
+ //Rules Adaptor Contsructor
41
+ function rules() {
42
+ return {
43
+ getRules: getRules.bind(this),
44
+ getParticularRule: getParticularRule.bind(this),
45
+ getUserRule: getUserRule.bind(this),
46
+ updateRuleDisplay: updateRuleDisplay.bind(this),
47
+ createRule: createRule.bind(this),
48
+ updateRule: updateRule.bind(this),
49
+ deleteRule: deleteRule.bind(this)
50
+ };
51
+ }
52
+
53
+ /*********************************
54
+ * Public Function definitions
55
+ **********************************/
56
+
57
+ /**
58
+ * Wiki Link for SDK params
59
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#getrulesparams
60
+ */
61
+ function getRules(options) {
62
+ var self = this;
63
+
64
+ //Initializing promise
65
+ var dfd = q.defer();
66
+
67
+ //Validations
68
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
69
+ if (err) {
70
+ dfd.reject(err);
71
+ } else {
72
+ if (options && options.context && options.ruleType) {
73
+ //Passed all validations, Contruct API url
74
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.rules;
75
+ url = helpers.api.constructAPIUrl(url, {
76
+ orgId: self.orgId,
77
+ context: encodeURIComponent(options.context),
78
+ ruleType: options.ruleType
79
+ });
80
+
81
+ //Setup request with URL and Params
82
+ var queryParam = { cursor: options.cursor };
83
+
84
+ var requestAPI = request.get(url)
85
+ .set('Content-Type', 'application/json')
86
+ .set('Accept', 'application/json')
87
+ .query(queryParam);
88
+
89
+ if (self.traceid) {
90
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
91
+ }
92
+
93
+ //Setup token in Authorization header
94
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
95
+
96
+ requestAPI.end(function (err, response) {
97
+ if (err) {
98
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
99
+ dfd.reject(err);
100
+ } else {
101
+ dfd.resolve(response.body);
102
+ }
103
+ });
104
+ } else {
105
+ err = {};
106
+ err.message = err.description = 'context or ruleType not found in request options.';
107
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
108
+ dfd.reject(err);
109
+ }
110
+ }
111
+ return dfd.promise;
112
+ }
113
+
114
+ /**
115
+ * Wiki Link for SDK params
116
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#getparticularruleparams
117
+ */
118
+ function getParticularRule(options) {
119
+ var self = this;
120
+
121
+ //Initializing promise
122
+ var dfd = q.defer();
123
+
124
+ //Validations
125
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
126
+ if (err) {
127
+ dfd.reject(err);
128
+ } else {
129
+ if (options && options.context && options.ruleType && options.ruleId) {
130
+ //Passed all validations, Contruct API url
131
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
132
+ url = helpers.api.constructAPIUrl(url, {
133
+ orgId: self.orgId,
134
+ context: encodeURIComponent(options.context),
135
+ ruleType: options.ruleType,
136
+ ruleId: options.ruleId
137
+ });
138
+
139
+ //Setup request with URL and Params
140
+ var requestAPI = request.get(url);
141
+
142
+ if (self.traceid) {
143
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
144
+ }
145
+
146
+ //Setup token in Authorization header
147
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
148
+
149
+ requestAPI.end(function (err, response) {
150
+ if (err) {
151
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
152
+ dfd.reject(err);
153
+ } else {
154
+ dfd.resolve(response.body);
155
+ }
156
+ });
157
+ } else {
158
+ err = {};
159
+ err.message = err.description = 'context or ruleType or ruleId not found' +
160
+ ' in request options.';
161
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
162
+ dfd.reject(err);
163
+ }
164
+ }
165
+ return dfd.promise;
166
+ }
167
+
168
+ /**
169
+ * Wiki Link for SDK params
170
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#getuserruleparams
171
+ */
172
+ function getUserRule(options) {
173
+ var self = this;
174
+
175
+ //Initializing promise
176
+ var dfd = q.defer();
177
+
178
+ if (options && options.orgId && options.context && options.ruleType && options.userId) {
179
+ //Passed all validations, Contruct API url
180
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.getUserRule;
181
+ url = helpers.api.constructAPIUrl(url, {
182
+ orgId: self.orgId,
183
+ context: encodeURIComponent(options.context),
184
+ ruleType: options.ruleType,
185
+ userId: options.userId
186
+ });
187
+
188
+ var requestAPI = request.get(url)
189
+ .set('Content-Type', 'application/json')
190
+ .set('Accept', 'application/json');
191
+
192
+ if (self.traceid) {
193
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
194
+ }
195
+
196
+ //Setup token in Authorization header
197
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
198
+
199
+ requestAPI
200
+ .agent(keepaliveAgent)
201
+ .end(function (err, response) {
202
+ if (err) {
203
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
204
+ dfd.reject(err);
205
+ } else {
206
+ dfd.resolve(response.body);
207
+ }
208
+ });
209
+ } else {
210
+ var err = {};
211
+ err.message = err.description = 'Mandatory params - orgId or context or ruleType or userId ' +
212
+ 'not found in request options.';
213
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
214
+ dfd.reject(err);
215
+ }
216
+
217
+ return dfd.promise;
218
+ }
219
+
220
+ /**
221
+ * Wiki Link for SDK params
222
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#updateruledisplayparams
223
+ */
224
+ function updateRuleDisplay(options) {
225
+ var self = this;
226
+ // Initializing promise
227
+ var dfd = q.defer();
228
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
229
+ if (err) { dfd.reject(err); }
230
+ else {
231
+ if (options && options.context && options.ruleType && options.ruleId &&
232
+ options.body && options.body.rule_display) {
233
+ // Passed all validations, Contruct API url
234
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.updateRuleDisplay;
235
+ url = helpers.api.constructAPIUrl(url, {
236
+ orgId: self.orgId,
237
+ context: encodeURIComponent(options.context),
238
+ ruleType: options.ruleType,
239
+ ruleId: options.ruleId
240
+ });
241
+
242
+ // Setup request with URL and Params
243
+ var requestAPI = request.put(url)
244
+ .set('Content-Type', 'application/json')
245
+ .set('Accept', 'application/json')
246
+ .send(options.body);
247
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
248
+
249
+ //Setup token in Authorization header
250
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
251
+
252
+ requestAPI.end(function (error, response) {
253
+ if (error) {
254
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
255
+ dfd.reject(err);
256
+ }
257
+ else { dfd.resolve(response.body); }
258
+ });
259
+ } else {
260
+ err = {};
261
+ err.message = err.description = 'Mandatory params - context or ruleType or ruleId ' +
262
+ 'or body.rule_display not found in request options.';
263
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
264
+ dfd.reject(err);
265
+ }
266
+ }
267
+ return dfd.promise;
268
+ }
269
+
270
+ /**
271
+ * Wiki Link for SDK params
272
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#createruleparams
273
+ */
274
+ function createRule(options) {
275
+ var self = this;
276
+ // Initializing promise
277
+ var dfd = q.defer();
278
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
279
+ if (err) { dfd.reject(err); }
280
+ else {
281
+ if (options && options.context && options.ruleType && options.body) {
282
+ // Passed all validations, Contruct API url
283
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.rules;
284
+ url = helpers.api.constructAPIUrl(url, {
285
+ orgId: self.orgId,
286
+ context: encodeURIComponent(options.context),
287
+ ruleType: options.ruleType
288
+ });
289
+
290
+ // Setup request with URL and Params
291
+ var requestAPI = request.post(url)
292
+ .set('Content-Type', 'application/json')
293
+ .set('Accept', 'application/json')
294
+ .send(options.body);
295
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
296
+
297
+ //Setup token in Authorization header
298
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
299
+
300
+ requestAPI.end(function (error, response) {
301
+ if (error) {
302
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
303
+ dfd.reject(err);
304
+ }
305
+ else { dfd.resolve(response.body); }
306
+ });
307
+ } else {
308
+ err = {};
309
+ err.message = err.description = 'Mandatory params - context or ruleType or body' +
310
+ ' not found in request options.';
311
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
312
+ dfd.reject(err);
313
+ }
314
+ }
315
+ return dfd.promise;
316
+ }
317
+
318
+ /**
319
+ * Wiki Link for SDK params
320
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#updateruleparams
321
+ */
322
+ function updateRule(options) {
323
+ var self = this;
324
+ // Initializing promise
325
+ var dfd = q.defer();
326
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
327
+ if (err) { dfd.reject(err); }
328
+ else {
329
+ if (options && options.context && options.ruleType && options.ruleId && options.body) {
330
+ // Passed all validations, Contruct API url
331
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
332
+ url = helpers.api.constructAPIUrl(url, {
333
+ orgId: self.orgId,
334
+ context: encodeURIComponent(options.context),
335
+ ruleType: options.ruleType,
336
+ ruleId: options.ruleId
337
+ });
338
+
339
+ // Setup request with URL and Params
340
+ var requestAPI = request.put(url)
341
+ .set('Content-Type', 'application/json')
342
+ .set('Accept', 'application/json')
343
+ .send(options.body);
344
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
345
+
346
+ //Setup token in Authorization header
347
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
348
+
349
+ requestAPI.end(function (error, response) {
350
+ if (error) {
351
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
352
+ dfd.reject(err);
353
+ }
354
+ else { dfd.resolve(response.body); }
355
+ });
356
+ } else {
357
+ err = {};
358
+ err.message = err.description = 'Mandatory params - context or ruleType or ruleId or body ' +
359
+ 'not found in request options.';
360
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
361
+ dfd.reject(err);
362
+ }
363
+ }
364
+ return dfd.promise;
365
+ }
366
+
367
+ /**
368
+ * Wiki Link for SDK params
369
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/26_RULES-Adaptor#deleteruleparams
370
+ */
371
+ function deleteRule(options) {
372
+ var self = this;
373
+ // Initializing promise
374
+ var dfd = q.defer();
375
+
376
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
377
+ if (err) { dfd.reject(err); }
378
+ else {
379
+ if (options && options.context && options.ruleType && options.ruleId) {
380
+ // Passed all validations, Contruct API url
381
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
382
+ url = helpers.api.constructAPIUrl(url, {
383
+ orgId: self.orgId,
384
+ context: encodeURIComponent(options.context),
385
+ ruleType: options.ruleType,
386
+ ruleId: options.ruleId
387
+ });
388
+
389
+ // Setup request with URL and Params
390
+ var requestAPI = request.delete(url);
391
+
392
+ //Setup token in Authorization header
393
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
394
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
395
+
396
+ requestAPI.end(function (error, response) {
397
+ if (error) {
398
+ err = {};
399
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
400
+ dfd.reject(err);
401
+ }
402
+ else {
403
+ dfd.resolve(response.body);
404
+ }
405
+ });
406
+ }
407
+ else {
408
+ err = {};
409
+ err.message = err.description = 'Mandatory params - context or ruleType or ruleId not found' +
410
+ ' in request options.';
411
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
412
+ dfd.reject(err);
413
+ }
414
+ }
415
+ return dfd.promise;
416
+ }