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,525 +1,525 @@
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 AUTH API Adaptor
23
- * Functions for calling AUTH API.
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 converter = require('../../helpers/lib/api/converter');
32
-
33
- var DLSError = helpers.errors.DLSError;
34
-
35
- module.exports = integrations;
36
-
37
- var keepaliveAgent = new Agent({
38
- timeout: 60000,
39
- freeSocketTimeout: 30000
40
- });
41
-
42
- //Integrations Adaptor Constructor
43
- function integrations(accountId) {
44
- this.accountId = accountId;
45
- return {
46
- getGetStreamCredentials: getGetStreamCredentials.bind(this),
47
- queryDataFromSearch: queryDataFromSearch.bind(this),
48
- getAuditTrailForAttempts: getAuditTrailForAttempts.bind(this),
49
- getAuditTrailForEntitlements: getAuditTrailForEntitlements.bind(this),
50
- getAuditTrailForMicroEntitlements: getAuditTrailForMicroEntitlements.bind(this),
51
- publishCustomEvents: publishCustomEvents.bind(this),
52
- createSchedule: createSchedule.bind(this),
53
- getSchedule: getSchedule.bind(this),
54
- updateSchedule: updateSchedule.bind(this),
55
- deleteSchedule: deleteSchedule.bind(this),
56
- publishEventsToRabbitMQ: publishEventsToRabbitMQ.bind(this)
57
- };
58
- }
59
-
60
- /** params: NONE */
61
- function getGetStreamCredentials() {
62
- var self = this;
63
- var dfd = q.defer(), err;
64
-
65
- var url = self.config.DEFAULT_HOSTS.INTEGRATION +
66
- self.config.INTEGRATIONS_API_URLS.getGetStreamCredentials;
67
- url = helpers.api.constructAPIUrl(url, { accountId: self.accountId });
68
-
69
- // Setup request with URL and Params
70
- var requestAPI = request.post(url)
71
- .set('Content-Type', 'application/json')
72
- .set('Accept', 'application/json')
73
- .send();
74
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
75
-
76
- requestAPI.end(function (error, response) {
77
- if(error) {
78
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
79
- dfd.reject(err);
80
- }
81
- else { dfd.resolve(response); }
82
- });
83
- return dfd.promise;
84
- }
85
-
86
- /**
87
- * Wiki Link for SDK params
88
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#querydatafromsearchparams
89
- */
90
- function queryDataFromSearch(options) {
91
- var self = this;
92
- var dfd = q.defer();
93
- var err;
94
-
95
- if(options && options.index && options.query) {
96
- //Passed all validations, Construct API url
97
- var url = self.config.DEFAULT_HOSTS.INTEGRATION +
98
- self.config.INTEGRATIONS_API_URLS.queryDataFromSearch;
99
- url = helpers.api.constructAPIUrl(url, { index: options.index });
100
-
101
- // Contruct parameters
102
- var params = {
103
- query: options.query
104
- };
105
-
106
- //Setup request with URL and Params
107
- var requestAPI = request.get(url).query(params);
108
-
109
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
110
-
111
- requestAPI.end(function (err, response) {
112
- if (err) {
113
- var esErrOptions = { type: helpers.errors.ERROR_TYPES.API_ERROR, err: err };
114
- var error = converter.convertElasticsearchErrResponse(esErrOptions);
115
- dfd.reject(error);
116
- }
117
- else { dfd.resolve(response.body); }
118
- });
119
- }
120
- else {
121
- err = {};
122
- err.message = err.description = 'Mandatory params - index, type or query ' +
123
- 'not found in request options.';
124
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
125
- dfd.reject(err);
126
- }
127
- return dfd.promise;
128
- }
129
-
130
- /**
131
- * Wiki Link for SDK params
132
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getaudittrailforattemptsparams
133
- */
134
- function getAuditTrailForAttempts(options) {
135
- var self = this;
136
- var dfd = q.defer();
137
- var err;
138
-
139
- if (options && options.accountid && options.action &&
140
- options.userid && options.productcode && options['item-code']) {
141
- //Passed all validations, Construct API url
142
- var url = self.config.DEFAULT_HOSTS.INTEGRATION +
143
- self.config.INTEGRATIONS_API_URLS.auditTrail;
144
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountid });
145
-
146
- // Contruct parameters
147
- var params = {
148
- audit_context: 'ATTEMPT-' + options.accountid + '#' + options.userid,
149
- target_context: 'PRODUCT-' + options.productcode + '#' + options['item-code'],
150
- action: options.action
151
- };
152
- if(options.cursor) { params.cursor = options.cursor; }
153
- if(options.sortOrder) { params.sortOrder = options.sortOrder; }
154
-
155
- //Setup request with URL and Params
156
- var requestAPI = request.get(url).query(params);
157
-
158
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
159
-
160
- requestAPI.end(function (err, response) {
161
- if(err) {
162
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
163
- dfd.reject(err);
164
- }
165
- else { dfd.resolve(response.body); }
166
- });
167
- }
168
- else {
169
- err = {};
170
- err.message = err.description = 'Mandatory params - accountid, action, userid, ' +
171
- 'productcode or item-code not found in request options.';
172
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
173
- dfd.reject(err);
174
- }
175
- return dfd.promise;
176
- }
177
-
178
- /**
179
- * Wiki Link for SDK params
180
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getaudittrailforentitlementsparams
181
- */
182
- function getAuditTrailForEntitlements(options) {
183
- var self = this;
184
- var dfd = q.defer();
185
- var err;
186
-
187
- if(options && options.accountid && options.action &&
188
- options.userid && options.productcode) {
189
- //Passed all validations, Construct API url
190
- var url = self.config.DEFAULT_HOSTS.INTEGRATION +
191
- self.config.INTEGRATIONS_API_URLS.auditTrail;
192
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountid });
193
-
194
- // Contruct parameters
195
- var params = {
196
- audit_context: 'ENTITLEMENT-' + options.accountid + '#' + options.userid,
197
- target_context: 'PRODUCT-' + options.productcode,
198
- type: 'entitlement',
199
- action: options.action
200
- };
201
- if(options.cursor) { params.cursor = options.cursor; }
202
- if(options.sortOrder) { params.sortOrder = options.sortOrder; }
203
-
204
- //Setup request with URL and Params
205
- var requestAPI = request.get(url).query(params);
206
-
207
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
208
-
209
- requestAPI.end(function (err, response) {
210
- if(err) {
211
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
212
- dfd.reject(err);
213
- }
214
- else { dfd.resolve(response.body); }
215
- });
216
- }
217
- else {
218
- err = {};
219
- err.message = err.description = 'Mandatory params - accountid, userid or productcode ' +
220
- 'not found in request options.';
221
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
222
- dfd.reject(err);
223
- }
224
- return dfd.promise;
225
- }
226
-
227
- /**
228
- * Wiki Link for SDK params
229
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getaudittrailformicroentitlementsparams
230
- */
231
- function getAuditTrailForMicroEntitlements(options) {
232
- var self = this;
233
- var dfd = q.defer();
234
- var err;
235
-
236
- if(options && options.accountid && options.action &&
237
- options.userid && options.productcode && options.context) {
238
- //Passed all validations, Construct API url
239
- var url = self.config.DEFAULT_HOSTS.INTEGRATION +
240
- self.config.INTEGRATIONS_API_URLS.auditTrail;
241
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountid });
242
-
243
- // Contruct parameters
244
- var params = {
245
- audit_context: 'ENTITLEMENT-' + options.accountid + '#' + options.userid,
246
- target_context: 'PRODUCT-' + options.productcode + '#' + options.context,
247
- type: 'micro-entitlement',
248
- action: options.action
249
- };
250
- if(options.cursor) { params.cursor = options.cursor; }
251
- if(options.sortOrder) { params.sortOrder = options.sortOrder; }
252
-
253
- //Setup request with URL and Params
254
- var requestAPI = request.get(url).query(params);
255
-
256
- if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
257
-
258
- requestAPI.end(function (err, response) {
259
- if(err){
260
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
261
- dfd.reject(err);
262
- }
263
- else { dfd.resolve(response.body); }
264
- });
265
- }
266
- else {
267
- err = {};
268
- err.message = err.description = 'Mandatory params - accountid, action, userid, productcode ' +
269
- 'or context not found in request options.';
270
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
271
- dfd.reject(err);
272
- }
273
- return dfd.promise;
274
- }
275
-
276
- /**
277
- * Wiki Link for SDK params
278
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#publishcustomeventsparams
279
- */
280
- function publishCustomEvents(options) {
281
- var deferred = q.defer();
282
- var self = this, err;
283
-
284
- if (options && options.events) {
285
- // Construct API url
286
- var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.customEvents;
287
- url = helpers.api.constructAPIUrl(url, { accountId: self.accountId });
288
-
289
- // Setup request with URL and Params
290
- var requestAPI = request.post(url)
291
- .set('Content-Type', 'application/json')
292
- .set('Accept', 'application/json')
293
- .send(options);
294
-
295
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
296
-
297
- requestAPI.end(function (error, response) {
298
- if (error) {
299
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
300
- deferred.reject(err);
301
- } else {
302
- deferred.resolve(response.body);
303
- }
304
- });
305
- } else {
306
- err = {};
307
- err.message = err.description = 'Mandatory params - events not found in request options.';
308
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
309
- deferred.reject(err);
310
- }
311
-
312
- return deferred.promise;
313
- }
314
-
315
- /**
316
- * Wiki Link for SDK params
317
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#createscheduleparams
318
- */
319
- function createSchedule(options) {
320
- var deferred = q.defer();
321
- // Initializing promise
322
- var self = this, err;
323
-
324
- if (options && options.context && options.accountid && options.body && (Object.keys(options.body).length > 0) &&
325
- options.body.scheduleid && options.body.actorid && options.body.category && options.body.schedule_time) {
326
- // Construct API url
327
- var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.schedules;
328
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context });
329
-
330
- // Setup request with URL and Params
331
- var requestAPI = request.post(url)
332
- .set('Content-Type', 'application/json')
333
- .set('Accept', 'application/json')
334
- .send(options.body);
335
-
336
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
337
-
338
- requestAPI.end(function (error, response) {
339
- if (error) {
340
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
341
- deferred.reject(err);
342
- } else {
343
- deferred.resolve(response.body);
344
- }
345
- });
346
- } else {
347
- err = {};
348
- err.message = err.description = 'Mandatory param - accountid or context or body(scheduleid or actorid or '+
349
- 'category or schedule_time) not found in request options.';
350
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
351
- deferred.reject(err);
352
- }
353
-
354
- return deferred.promise;
355
- }
356
-
357
- /**
358
- * Wiki Link for SDK params
359
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getscheduleparams
360
- */
361
- function getSchedule(options) {
362
- var deferred = q.defer();
363
- // Initializing promise
364
- var self = this, err;
365
-
366
- if (options && options.context && options.accountid) {
367
- // Construct API url
368
- var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.schedules;
369
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context });
370
-
371
- var params = {};
372
- if(options.cursor) { params.cursor = options.cursor; }
373
- if(options.category) { params.category = options.category; }
374
- if(options.scheduleid) { params.scheduleid = options.scheduleid; }
375
-
376
- //Setup request with URL and Params
377
- var requestAPI = request.get(url).query(params);
378
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
379
-
380
- requestAPI.end(function (error, response) {
381
- if (error) {
382
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
383
- deferred.reject(err);
384
- } else {
385
- deferred.resolve(response.body);
386
- }
387
- });
388
- } else {
389
- err = {};
390
- err.message = err.description = 'Mandatory params - accountid or context not found in request options.';
391
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
392
- deferred.reject(err);
393
- }
394
-
395
- return deferred.promise;
396
- }
397
-
398
- /**
399
- * Wiki Link for SDK params
400
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#updatescheduleparams
401
- */
402
- function updateSchedule(options) {
403
- var deferred = q.defer();
404
- // Initializing promise
405
- var self = this, err;
406
-
407
- if (options && options.context && options.accountid && options.scheduleid && options.body &&
408
- (Object.keys(options.body).length > 0) && options.body.actorid && options.body.category) {
409
- // Construct API url
410
- var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.particularSchedule;
411
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context, scheduleId: options.scheduleid });
412
-
413
- // Setup request with URL and Params
414
- var requestAPI = request.put(url)
415
- .set('Content-Type', 'application/json')
416
- .set('Accept', 'application/json')
417
- .send(options.body);
418
-
419
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
420
-
421
- requestAPI.end(function (error, response) {
422
- if (error) {
423
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
424
- deferred.reject(err);
425
- } else {
426
- deferred.resolve(response.body);
427
- }
428
- });
429
- } else {
430
- err = {};
431
- err.message = err.description = 'Mandatory param - accountid or context or scheduleid or ' +
432
- 'body(category or actorid) not found in request options.';
433
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
434
- deferred.reject(err);
435
- }
436
-
437
- return deferred.promise;
438
- }
439
-
440
- /**
441
- * Wiki Link for SDK params
442
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#deletescheduleparams
443
- */
444
- function deleteSchedule(options) {
445
- var deferred = q.defer();
446
- // Initializing promise
447
- var self = this, err;
448
-
449
- if (options && options.context && options.accountid && options.scheduleid && options.body) {
450
- // Construct API url
451
- var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.particularSchedule;
452
- url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context, scheduleId: options.scheduleid });
453
-
454
- // Setup request with URL and Params
455
- var requestAPI = request.delete(url)
456
- .set('Content-Type', 'application/json')
457
- .set('Accept', 'application/json')
458
- .send(options.body);
459
-
460
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
461
-
462
- requestAPI
463
- .agent(keepaliveAgent)
464
- .end(function (error, response) {
465
- if (error) {
466
- err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
467
- deferred.reject(err);
468
- } else {
469
- deferred.resolve(response.body);
470
- }
471
- });
472
- } else {
473
- err = {};
474
- err.message = err.description = 'Mandatory param - accountid or context or scheduleid or ' +
475
- 'body not found in request options.';
476
- err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
477
- deferred.reject(err);
478
- }
479
-
480
- return deferred.promise;
481
- }
482
-
483
- /**
484
- * Wiki Link for SDK params
485
- * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#publisheventstorabbitmqparams
486
- */
487
- function publishEventsToRabbitMQ(options) {
488
- var self = this;
489
- console.log('Publishing events to RabbitMQ with options in the publishEventsToRabbitMQ function:', JSON.stringify(options, null, 2));
490
-
491
- return new Promise(function (resolve, reject) {
492
- if (options && options.route && options.route.exchange && options.route.routingKey &&
493
- options.data && options.data.context) {
494
- // Construct API url
495
- var url = self.config.DEFAULT_HOSTS.INTEGRATION +
496
- self.config.INTEGRATIONS_API_URLS.bridgeToRabbitMQ;
497
-
498
- var body = {
499
- route: options.route,
500
- data: options.data
501
- };
502
-
503
- // Setup request with URL and Params
504
- var requestAPI = request.post(url)
505
- .set('Content-Type', 'application/json')
506
- .set('Accept', 'application/json')
507
- .send(body);
508
-
509
- if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
510
-
511
- requestAPI.end(function (error, response) {
512
- if (error) {
513
- reject(new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error));
514
- } else {
515
- resolve(response.body);
516
- }
517
- });
518
- } else {
519
- var err = {};
520
- err.message = err.description = 'Mandatory params - route(exchange or routingKey) or ' +
521
- 'data(context) not found in request options.';
522
- reject(new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err));
523
- }
524
- });
525
- }
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 AUTH API Adaptor
23
+ * Functions for calling AUTH API.
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 converter = require('../../helpers/lib/api/converter');
32
+
33
+ var DLSError = helpers.errors.DLSError;
34
+
35
+ module.exports = integrations;
36
+
37
+ var keepaliveAgent = new Agent({
38
+ timeout: 60000,
39
+ freeSocketTimeout: 30000
40
+ });
41
+
42
+ //Integrations Adaptor Constructor
43
+ function integrations(accountId) {
44
+ this.accountId = accountId;
45
+ return {
46
+ getGetStreamCredentials: getGetStreamCredentials.bind(this),
47
+ queryDataFromSearch: queryDataFromSearch.bind(this),
48
+ getAuditTrailForAttempts: getAuditTrailForAttempts.bind(this),
49
+ getAuditTrailForEntitlements: getAuditTrailForEntitlements.bind(this),
50
+ getAuditTrailForMicroEntitlements: getAuditTrailForMicroEntitlements.bind(this),
51
+ publishCustomEvents: publishCustomEvents.bind(this),
52
+ createSchedule: createSchedule.bind(this),
53
+ getSchedule: getSchedule.bind(this),
54
+ updateSchedule: updateSchedule.bind(this),
55
+ deleteSchedule: deleteSchedule.bind(this),
56
+ publishEventsToRabbitMQ: publishEventsToRabbitMQ.bind(this)
57
+ };
58
+ }
59
+
60
+ /** params: NONE */
61
+ function getGetStreamCredentials() {
62
+ var self = this;
63
+ var dfd = q.defer(), err;
64
+
65
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION +
66
+ self.config.INTEGRATIONS_API_URLS.getGetStreamCredentials;
67
+ url = helpers.api.constructAPIUrl(url, { accountId: self.accountId });
68
+
69
+ // Setup request with URL and Params
70
+ var requestAPI = request.post(url)
71
+ .set('Content-Type', 'application/json')
72
+ .set('Accept', 'application/json')
73
+ .send();
74
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
75
+
76
+ requestAPI.end(function (error, response) {
77
+ if(error) {
78
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
79
+ dfd.reject(err);
80
+ }
81
+ else { dfd.resolve(response); }
82
+ });
83
+ return dfd.promise;
84
+ }
85
+
86
+ /**
87
+ * Wiki Link for SDK params
88
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#querydatafromsearchparams
89
+ */
90
+ function queryDataFromSearch(options) {
91
+ var self = this;
92
+ var dfd = q.defer();
93
+ var err;
94
+
95
+ if(options && options.index && options.query) {
96
+ //Passed all validations, Construct API url
97
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION +
98
+ self.config.INTEGRATIONS_API_URLS.queryDataFromSearch;
99
+ url = helpers.api.constructAPIUrl(url, { index: options.index });
100
+
101
+ // Contruct parameters
102
+ var params = {
103
+ query: options.query
104
+ };
105
+
106
+ //Setup request with URL and Params
107
+ var requestAPI = request.get(url).query(params);
108
+
109
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
110
+
111
+ requestAPI.end(function (err, response) {
112
+ if (err) {
113
+ var esErrOptions = { type: helpers.errors.ERROR_TYPES.API_ERROR, err: err };
114
+ var error = converter.convertElasticsearchErrResponse(esErrOptions);
115
+ dfd.reject(error);
116
+ }
117
+ else { dfd.resolve(response.body); }
118
+ });
119
+ }
120
+ else {
121
+ err = {};
122
+ err.message = err.description = 'Mandatory params - index, type or query ' +
123
+ 'not found in request options.';
124
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
125
+ dfd.reject(err);
126
+ }
127
+ return dfd.promise;
128
+ }
129
+
130
+ /**
131
+ * Wiki Link for SDK params
132
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getaudittrailforattemptsparams
133
+ */
134
+ function getAuditTrailForAttempts(options) {
135
+ var self = this;
136
+ var dfd = q.defer();
137
+ var err;
138
+
139
+ if (options && options.accountid && options.action &&
140
+ options.userid && options.productcode && options['item-code']) {
141
+ //Passed all validations, Construct API url
142
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION +
143
+ self.config.INTEGRATIONS_API_URLS.auditTrail;
144
+ url = helpers.api.constructAPIUrl(url, { accountId: options.accountid });
145
+
146
+ // Contruct parameters
147
+ var params = {
148
+ audit_context: 'ATTEMPT-' + options.accountid + '#' + options.userid,
149
+ target_context: 'PRODUCT-' + options.productcode + '#' + options['item-code'],
150
+ action: options.action
151
+ };
152
+ if(options.cursor) { params.cursor = options.cursor; }
153
+ if(options.sortOrder) { params.sortOrder = options.sortOrder; }
154
+
155
+ //Setup request with URL and Params
156
+ var requestAPI = request.get(url).query(params);
157
+
158
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
159
+
160
+ requestAPI.end(function (err, response) {
161
+ if(err) {
162
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
163
+ dfd.reject(err);
164
+ }
165
+ else { dfd.resolve(response.body); }
166
+ });
167
+ }
168
+ else {
169
+ err = {};
170
+ err.message = err.description = 'Mandatory params - accountid, action, userid, ' +
171
+ 'productcode or item-code not found in request options.';
172
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
173
+ dfd.reject(err);
174
+ }
175
+ return dfd.promise;
176
+ }
177
+
178
+ /**
179
+ * Wiki Link for SDK params
180
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getaudittrailforentitlementsparams
181
+ */
182
+ function getAuditTrailForEntitlements(options) {
183
+ var self = this;
184
+ var dfd = q.defer();
185
+ var err;
186
+
187
+ if(options && options.accountid && options.action &&
188
+ options.userid && options.productcode) {
189
+ //Passed all validations, Construct API url
190
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION +
191
+ self.config.INTEGRATIONS_API_URLS.auditTrail;
192
+ url = helpers.api.constructAPIUrl(url, { accountId: options.accountid });
193
+
194
+ // Contruct parameters
195
+ var params = {
196
+ audit_context: 'ENTITLEMENT-' + options.accountid + '#' + options.userid,
197
+ target_context: 'PRODUCT-' + options.productcode,
198
+ type: 'entitlement',
199
+ action: options.action
200
+ };
201
+ if(options.cursor) { params.cursor = options.cursor; }
202
+ if(options.sortOrder) { params.sortOrder = options.sortOrder; }
203
+
204
+ //Setup request with URL and Params
205
+ var requestAPI = request.get(url).query(params);
206
+
207
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
208
+
209
+ requestAPI.end(function (err, response) {
210
+ if(err) {
211
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
212
+ dfd.reject(err);
213
+ }
214
+ else { dfd.resolve(response.body); }
215
+ });
216
+ }
217
+ else {
218
+ err = {};
219
+ err.message = err.description = 'Mandatory params - accountid, userid or productcode ' +
220
+ 'not found in request options.';
221
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
222
+ dfd.reject(err);
223
+ }
224
+ return dfd.promise;
225
+ }
226
+
227
+ /**
228
+ * Wiki Link for SDK params
229
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getaudittrailformicroentitlementsparams
230
+ */
231
+ function getAuditTrailForMicroEntitlements(options) {
232
+ var self = this;
233
+ var dfd = q.defer();
234
+ var err;
235
+
236
+ if(options && options.accountid && options.action &&
237
+ options.userid && options.productcode && options.context) {
238
+ //Passed all validations, Construct API url
239
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION +
240
+ self.config.INTEGRATIONS_API_URLS.auditTrail;
241
+ url = helpers.api.constructAPIUrl(url, { accountId: options.accountid });
242
+
243
+ // Contruct parameters
244
+ var params = {
245
+ audit_context: 'ENTITLEMENT-' + options.accountid + '#' + options.userid,
246
+ target_context: 'PRODUCT-' + options.productcode + '#' + options.context,
247
+ type: 'micro-entitlement',
248
+ action: options.action
249
+ };
250
+ if(options.cursor) { params.cursor = options.cursor; }
251
+ if(options.sortOrder) { params.sortOrder = options.sortOrder; }
252
+
253
+ //Setup request with URL and Params
254
+ var requestAPI = request.get(url).query(params);
255
+
256
+ if(self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
257
+
258
+ requestAPI.end(function (err, response) {
259
+ if(err){
260
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
261
+ dfd.reject(err);
262
+ }
263
+ else { dfd.resolve(response.body); }
264
+ });
265
+ }
266
+ else {
267
+ err = {};
268
+ err.message = err.description = 'Mandatory params - accountid, action, userid, productcode ' +
269
+ 'or context not found in request options.';
270
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
271
+ dfd.reject(err);
272
+ }
273
+ return dfd.promise;
274
+ }
275
+
276
+ /**
277
+ * Wiki Link for SDK params
278
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#publishcustomeventsparams
279
+ */
280
+ function publishCustomEvents(options) {
281
+ var deferred = q.defer();
282
+ var self = this, err;
283
+
284
+ if (options && options.events) {
285
+ // Construct API url
286
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.customEvents;
287
+ url = helpers.api.constructAPIUrl(url, { accountId: self.accountId });
288
+
289
+ // Setup request with URL and Params
290
+ var requestAPI = request.post(url)
291
+ .set('Content-Type', 'application/json')
292
+ .set('Accept', 'application/json')
293
+ .send(options);
294
+
295
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
296
+
297
+ requestAPI.end(function (error, response) {
298
+ if (error) {
299
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
300
+ deferred.reject(err);
301
+ } else {
302
+ deferred.resolve(response.body);
303
+ }
304
+ });
305
+ } else {
306
+ err = {};
307
+ err.message = err.description = 'Mandatory params - events not found in request options.';
308
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
309
+ deferred.reject(err);
310
+ }
311
+
312
+ return deferred.promise;
313
+ }
314
+
315
+ /**
316
+ * Wiki Link for SDK params
317
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#createscheduleparams
318
+ */
319
+ function createSchedule(options) {
320
+ var deferred = q.defer();
321
+ // Initializing promise
322
+ var self = this, err;
323
+
324
+ if (options && options.context && options.accountid && options.body && (Object.keys(options.body).length > 0) &&
325
+ options.body.scheduleid && options.body.actorid && options.body.category && options.body.schedule_time) {
326
+ // Construct API url
327
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.schedules;
328
+ url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context });
329
+
330
+ // Setup request with URL and Params
331
+ var requestAPI = request.post(url)
332
+ .set('Content-Type', 'application/json')
333
+ .set('Accept', 'application/json')
334
+ .send(options.body);
335
+
336
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
337
+
338
+ requestAPI.end(function (error, response) {
339
+ if (error) {
340
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
341
+ deferred.reject(err);
342
+ } else {
343
+ deferred.resolve(response.body);
344
+ }
345
+ });
346
+ } else {
347
+ err = {};
348
+ err.message = err.description = 'Mandatory param - accountid or context or body(scheduleid or actorid or '+
349
+ 'category or schedule_time) not found in request options.';
350
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
351
+ deferred.reject(err);
352
+ }
353
+
354
+ return deferred.promise;
355
+ }
356
+
357
+ /**
358
+ * Wiki Link for SDK params
359
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#getscheduleparams
360
+ */
361
+ function getSchedule(options) {
362
+ var deferred = q.defer();
363
+ // Initializing promise
364
+ var self = this, err;
365
+
366
+ if (options && options.context && options.accountid) {
367
+ // Construct API url
368
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.schedules;
369
+ url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context });
370
+
371
+ var params = {};
372
+ if(options.cursor) { params.cursor = options.cursor; }
373
+ if(options.category) { params.category = options.category; }
374
+ if(options.scheduleid) { params.scheduleid = options.scheduleid; }
375
+
376
+ //Setup request with URL and Params
377
+ var requestAPI = request.get(url).query(params);
378
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
379
+
380
+ requestAPI.end(function (error, response) {
381
+ if (error) {
382
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
383
+ deferred.reject(err);
384
+ } else {
385
+ deferred.resolve(response.body);
386
+ }
387
+ });
388
+ } else {
389
+ err = {};
390
+ err.message = err.description = 'Mandatory params - accountid or context not found in request options.';
391
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
392
+ deferred.reject(err);
393
+ }
394
+
395
+ return deferred.promise;
396
+ }
397
+
398
+ /**
399
+ * Wiki Link for SDK params
400
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#updatescheduleparams
401
+ */
402
+ function updateSchedule(options) {
403
+ var deferred = q.defer();
404
+ // Initializing promise
405
+ var self = this, err;
406
+
407
+ if (options && options.context && options.accountid && options.scheduleid && options.body &&
408
+ (Object.keys(options.body).length > 0) && options.body.actorid && options.body.category) {
409
+ // Construct API url
410
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.particularSchedule;
411
+ url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context, scheduleId: options.scheduleid });
412
+
413
+ // Setup request with URL and Params
414
+ var requestAPI = request.put(url)
415
+ .set('Content-Type', 'application/json')
416
+ .set('Accept', 'application/json')
417
+ .send(options.body);
418
+
419
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
420
+
421
+ requestAPI.end(function (error, response) {
422
+ if (error) {
423
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
424
+ deferred.reject(err);
425
+ } else {
426
+ deferred.resolve(response.body);
427
+ }
428
+ });
429
+ } else {
430
+ err = {};
431
+ err.message = err.description = 'Mandatory param - accountid or context or scheduleid or ' +
432
+ 'body(category or actorid) not found in request options.';
433
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
434
+ deferred.reject(err);
435
+ }
436
+
437
+ return deferred.promise;
438
+ }
439
+
440
+ /**
441
+ * Wiki Link for SDK params
442
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#deletescheduleparams
443
+ */
444
+ function deleteSchedule(options) {
445
+ var deferred = q.defer();
446
+ // Initializing promise
447
+ var self = this, err;
448
+
449
+ if (options && options.context && options.accountid && options.scheduleid && options.body) {
450
+ // Construct API url
451
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION + self.config.INTEGRATIONS_API_URLS.particularSchedule;
452
+ url = helpers.api.constructAPIUrl(url, { accountId: options.accountid, context: options.context, scheduleId: options.scheduleid });
453
+
454
+ // Setup request with URL and Params
455
+ var requestAPI = request.delete(url)
456
+ .set('Content-Type', 'application/json')
457
+ .set('Accept', 'application/json')
458
+ .send(options.body);
459
+
460
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
461
+
462
+ requestAPI
463
+ .agent(keepaliveAgent)
464
+ .end(function (error, response) {
465
+ if (error) {
466
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
467
+ deferred.reject(err);
468
+ } else {
469
+ deferred.resolve(response.body);
470
+ }
471
+ });
472
+ } else {
473
+ err = {};
474
+ err.message = err.description = 'Mandatory param - accountid or context or scheduleid or ' +
475
+ 'body not found in request options.';
476
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
477
+ deferred.reject(err);
478
+ }
479
+
480
+ return deferred.promise;
481
+ }
482
+
483
+ /**
484
+ * Wiki Link for SDK params
485
+ * https://github.com/comprodls/comprodls-sdk-js/wiki/22_Integrations-Adapter#publisheventstorabbitmqparams
486
+ */
487
+ function publishEventsToRabbitMQ(options) {
488
+ var self = this;
489
+ console.log('Publishing events to RabbitMQ with options in the publishEventsToRabbitMQ function:', JSON.stringify(options, null, 2));
490
+
491
+ return new Promise(function (resolve, reject) {
492
+ if (options && options.route && options.route.exchange && options.route.routingKey &&
493
+ options.data && options.data.context) {
494
+ // Construct API url
495
+ var url = self.config.DEFAULT_HOSTS.INTEGRATION +
496
+ self.config.INTEGRATIONS_API_URLS.bridgeToRabbitMQ;
497
+
498
+ var body = {
499
+ route: options.route,
500
+ data: options.data
501
+ };
502
+
503
+ // Setup request with URL and Params
504
+ var requestAPI = request.post(url)
505
+ .set('Content-Type', 'application/json')
506
+ .set('Accept', 'application/json')
507
+ .send(body);
508
+
509
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
510
+
511
+ requestAPI.end(function (error, response) {
512
+ if (error) {
513
+ reject(new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error));
514
+ } else {
515
+ resolve(response.body);
516
+ }
517
+ });
518
+ } else {
519
+ var err = {};
520
+ err.message = err.description = 'Mandatory params - route(exchange or routingKey) or ' +
521
+ 'data(context) not found in request options.';
522
+ reject(new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err));
523
+ }
524
+ });
525
+ }