comprodls-sdk 2.115.0 → 2.119.1-security
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/comprodls-sdk.js +1190 -134
- package/dist/comprodls-sdk.min.js +1 -1
- package/lib/config/index.js +2 -1
- package/lib/helpers/lib/validator.js +53 -131
- package/lib/services/integrations/index.js +46 -1
- package/package.json +3 -2
package/lib/config/index.js
CHANGED
|
@@ -333,7 +333,8 @@ exports.INTEGRATIONS_API_URLS = {
|
|
|
333
333
|
auditTrail: '/accounts/{accountId}/audit-trail',
|
|
334
334
|
customEvents: '/accounts/{accountId}/custom-events',
|
|
335
335
|
schedules: '/accounts/{accountId}/context/{context}/schedule',
|
|
336
|
-
particularSchedule: '/accounts/{accountId}/context/{context}/schedule/{scheduleId}'
|
|
336
|
+
particularSchedule: '/accounts/{accountId}/context/{context}/schedule/{scheduleId}',
|
|
337
|
+
bridgeToRabbitMQ: '/events/bridge-to-rabbitmq'
|
|
337
338
|
};
|
|
338
339
|
|
|
339
340
|
exports.DRIVE_API_URLS = {
|
|
@@ -22,129 +22,13 @@
|
|
|
22
22
|
* comproDLS SDK Validator Helper Module
|
|
23
23
|
* This module contains validation helper functions for comproDLS SDK
|
|
24
24
|
************************************************************/
|
|
25
|
-
|
|
25
|
+
var validator = require('validate.js');
|
|
26
26
|
var errors = require('./errors');
|
|
27
27
|
var DLSError = errors.DLSError;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* fn(field, value, options) → DLSError | undefined
|
|
33
|
-
*
|
|
34
|
-
* - field : the constraint key name e.g. 'organization', 'token', 'token.access_token'
|
|
35
|
-
* - value : the value from the options object for that field
|
|
36
|
-
* - options : the rule config, can be `true` or `{ message: '...' }`
|
|
37
|
-
* For `contains`, options is a string or array of required keys.
|
|
38
|
-
*
|
|
39
|
-
* Returning a DLSError which stops validation immediately.
|
|
40
|
-
* Returning undefined means the check passed.
|
|
41
|
-
**********************************/
|
|
42
|
-
var validators = {
|
|
43
|
-
/**
|
|
44
|
-
* Fails if value is null, undefined, or blank/whitespace-only string or empty object.
|
|
45
|
-
*/
|
|
46
|
-
presence: function(field, value, options) {
|
|
47
|
-
if (value === undefined || value === null || value === '' ||
|
|
48
|
-
(typeof value == 'string' && value.trim() === '') ||
|
|
49
|
-
(typeof value == 'object' && Object.keys(value).length === 0)
|
|
50
|
-
) {
|
|
51
|
-
return createError(options.message || field + ' can\'t be blank');
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Fails if value is not a string.
|
|
57
|
-
*/
|
|
58
|
-
isString: function(field, value, options) {
|
|
59
|
-
if (typeof value !== 'string') {
|
|
60
|
-
return createError(options.message || field + ' is not a valid string');
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Fails if value is not an object.
|
|
66
|
-
*/
|
|
67
|
-
isObject: function(field, value, options) {
|
|
68
|
-
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
69
|
-
return createError(options.message || field + ' is not a valid object');
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Fails if the object does not have the required key(s).
|
|
75
|
-
*/
|
|
76
|
-
contains: function(field, value, options) {
|
|
77
|
-
var keys = Array.isArray(options) ? options : typeof options === 'string' ? [options] : [];
|
|
78
|
-
|
|
79
|
-
for (var i = 0; i < keys.length; i++) {
|
|
80
|
-
var requiredKey = keys[i];
|
|
81
|
-
|
|
82
|
-
if (!value.hasOwnProperty(requiredKey)) {
|
|
83
|
-
return createError(options.message || field + ' does not contain ' + requiredKey);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/*********************************
|
|
90
|
-
* Core validate function
|
|
91
|
-
*
|
|
92
|
-
* Iterates over each field in constraints, resolves its value from options,
|
|
93
|
-
* then runs each rule's validator function in order.
|
|
94
|
-
* Returns the first error encountered or undefined if all pass.
|
|
95
|
-
*
|
|
96
|
-
* @param {Object} options - The input object to validate
|
|
97
|
-
* @param {Object} constraints - Map of field names to their rule constraints
|
|
98
|
-
* @returns {DLSError | undefined}
|
|
99
|
-
**********************************/
|
|
100
|
-
function validate(options, constraints) {
|
|
101
|
-
for (var field in constraints) {
|
|
102
|
-
var fieldConstraintsObj = constraints[field];
|
|
103
|
-
var value = getValue(options, field);
|
|
104
|
-
|
|
105
|
-
for (var ruleName in fieldConstraintsObj) {
|
|
106
|
-
var ruleOptions = fieldConstraintsObj[ruleName];
|
|
107
|
-
var validatorFn = validators[ruleName];
|
|
108
|
-
|
|
109
|
-
if (!validatorFn) { continue; }
|
|
110
|
-
|
|
111
|
-
// Pass field name, field value, and field's rule constraint value to the validator function
|
|
112
|
-
var error = validatorFn(field, value, ruleOptions);
|
|
113
|
-
if (error) { return error; }
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/*********************************
|
|
121
|
-
* Private helpers
|
|
122
|
-
**********************************/
|
|
123
|
-
function getValue(obj, path) {
|
|
124
|
-
var keys = path.split('.');
|
|
125
|
-
var result = obj;
|
|
126
|
-
|
|
127
|
-
for (var i = 0; i < keys.length; i++) {
|
|
128
|
-
if (result === undefined || result === null) { return undefined; }
|
|
129
|
-
result = result[keys[i]];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function createError(message) {
|
|
136
|
-
var msg = message || 'Validation error';
|
|
137
|
-
msg = msg.charAt(0).toUpperCase() + msg.slice(1);
|
|
138
|
-
|
|
139
|
-
return new DLSError(errors.ERROR_TYPES.SDK_ERROR, {
|
|
140
|
-
message: msg,
|
|
141
|
-
description: msg
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/*********************************
|
|
146
|
-
* Exported auth validators
|
|
147
|
-
**********************************/
|
|
29
|
+
exports.validate = validate;
|
|
30
|
+
exports.isAuthenticated = validateIsAuthenticated;
|
|
31
|
+
exports.isAuthenticatedV2 = validateIsAuthenticatedV2;
|
|
148
32
|
|
|
149
33
|
/**
|
|
150
34
|
* This function validates if the SDK instance is authenticated.
|
|
@@ -161,10 +45,22 @@ function validateIsAuthenticatedV2(orgId, token) {
|
|
|
161
45
|
return new DLSError(errors.ERROR_TYPES.SDK_ERROR, errObj);
|
|
162
46
|
};
|
|
163
47
|
|
|
48
|
+
function validate(options, constraints) {
|
|
49
|
+
var err = {};
|
|
50
|
+
var validation_errors = validator(options, constraints);
|
|
51
|
+
if (validation_errors) {
|
|
52
|
+
for (var validation_error in validation_errors) {
|
|
53
|
+
err.message = err.description = validation_errors[validation_error][0];
|
|
54
|
+
err = new DLSError(errors.ERROR_TYPES.SDK_ERROR, err);
|
|
55
|
+
return err;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
164
62
|
/**
|
|
165
|
-
*
|
|
166
|
-
* @param {String} orgId - Organization ID
|
|
167
|
-
* @param {Object} token - Token object { access_token: 'string' }
|
|
63
|
+
* This function is deprecated. Please use validateIsAuthenticatedV2 instead.
|
|
168
64
|
*/
|
|
169
65
|
function validateIsAuthenticated(orgId, token) {
|
|
170
66
|
var validate_options = {
|
|
@@ -172,21 +68,47 @@ function validateIsAuthenticated(orgId, token) {
|
|
|
172
68
|
'token': token
|
|
173
69
|
};
|
|
174
70
|
|
|
175
|
-
var errMsg = 'SDK Instance does not have valid orgid or token. ' +
|
|
176
|
-
'Please authenticate using authWithCredentials or authWithToken method.';
|
|
177
|
-
|
|
178
71
|
var validate_constraints = {
|
|
179
72
|
'organization': {
|
|
180
|
-
'presence': {
|
|
73
|
+
'presence': {
|
|
74
|
+
'message' : '^SDK Instance does not have valid orgid or token. Please authenticate using authWithCredentials or authWithToken method.'
|
|
75
|
+
}
|
|
181
76
|
},
|
|
182
77
|
'token': {
|
|
183
|
-
'presence': {
|
|
78
|
+
'presence': {
|
|
79
|
+
'message' : '^SDK Instance does not have valid orgid or token. Please authenticate using authWithCredentials or authWithToken method.'
|
|
80
|
+
}
|
|
184
81
|
}
|
|
185
82
|
};
|
|
186
83
|
|
|
187
84
|
return validate(validate_options, validate_constraints);
|
|
188
85
|
};
|
|
189
86
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
87
|
+
/*********************************
|
|
88
|
+
* Private Function definitions
|
|
89
|
+
**********************************/
|
|
90
|
+
validator.validators.isString = function(value, options) {
|
|
91
|
+
if (!validator.isString(value)) {
|
|
92
|
+
return options.message || 'is not a valid string';
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
validator.validators.isObject = function(value, options) {
|
|
97
|
+
if (!validator.isObject(value)) {
|
|
98
|
+
return options.message || 'is not a valid object';
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
validator.validators.contains = function(value, options) {
|
|
103
|
+
if (validator.isArray(options)) {
|
|
104
|
+
for (var key in options) {
|
|
105
|
+
if (!value || !value.hasOwnProperty(options[key])) {
|
|
106
|
+
return options.message || 'does not contain ' + options[key];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} else if (validator.isString(options)) {
|
|
110
|
+
if (!value || !value.hasOwnProperty(options)) {
|
|
111
|
+
return options.message || 'does not contain ' + options;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
@@ -52,7 +52,8 @@ function integrations(accountId) {
|
|
|
52
52
|
createSchedule: createSchedule.bind(this),
|
|
53
53
|
getSchedule: getSchedule.bind(this),
|
|
54
54
|
updateSchedule: updateSchedule.bind(this),
|
|
55
|
-
deleteSchedule: deleteSchedule.bind(this)
|
|
55
|
+
deleteSchedule: deleteSchedule.bind(this),
|
|
56
|
+
publishEventsToRabbitMQ: publishEventsToRabbitMQ.bind(this)
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -478,3 +479,47 @@ function deleteSchedule(options) {
|
|
|
478
479
|
|
|
479
480
|
return deferred.promise;
|
|
480
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comprodls-sdk",
|
|
3
3
|
"description": "comproDLS SDK for JavaScript",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.119.1-security",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Compro Technologies Private Limited",
|
|
7
7
|
"url": "http://www.comprotechnologies.com/"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"pubnub": "7.5.0",
|
|
17
17
|
"q": "~1.4.1",
|
|
18
18
|
"string-template": "^1.0.0",
|
|
19
|
-
"superagent": "3.8.3"
|
|
19
|
+
"superagent": "3.8.3",
|
|
20
|
+
"validate.js": "^0.9.0"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"grunt": "^0.4.5",
|