comprodls-sdk 2.90.3-development → 2.91.0-thor
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/README.md +1 -137
- package/dist/comprodls-sdk.js +2917 -6291
- package/dist/comprodls-sdk.min.js +1 -1
- package/lib/comprodls.js +39 -57
- package/lib/config/index.js +172 -198
- package/lib/helpers/index.js +3 -2
- package/lib/helpers/lib/api/converter.js +1 -2
- package/lib/helpers/lib/api/index.js +19 -94
- package/lib/helpers/lib/errors.js +75 -80
- package/lib/helpers/lib/requestLayer.js +154 -0
- package/lib/helpers/lib/validator.js +65 -52
- package/lib/open_access/index.js +48 -53
- package/lib/services/analytics/index.js +286 -1014
- package/lib/services/attempts/index.js +38 -88
- package/lib/services/auth/index.js +324 -806
- package/lib/services/authextn/index.js +85 -247
- package/lib/services/datasyncmanager/index.js +10 -45
- package/lib/services/drive/index.js +20 -83
- package/lib/services/integrations/index.js +51 -126
- package/lib/services/invitations/index.js +20 -61
- package/lib/services/product/index.js +82 -85
- package/lib/services/pub/index.js +167 -235
- package/lib/services/pushX/index.js +195 -142
- package/lib/services/pushX/pubnubClientWrapper.js +399 -172
- package/lib/services/rules/index.js +14 -67
- package/lib/services/spaces/index.js +106 -289
- package/lib/services/spacesextn/index.js +44 -20
- package/lib/services/superuser/index.js +21 -36
- package/lib/services/taxonomy/index.js +27 -57
- package/lib/services/workflows/index.js +38 -97
- package/lib/services/xapi/index.js +7 -168
- package/lib/token/index.js +73 -67
- package/lib/token/validations.js +45 -48
- package/package.json +2 -3
- package/lib/helpers/lib/api/validations.js +0 -73
- package/lib/helpers/lib/utils.js +0 -24
- package/lib/services/activity/activity.js +0 -209
- package/lib/services/activity/attempt.js +0 -431
- package/lib/services/activity/index.js +0 -28
- package/lib/services/auth/classProduct.js +0 -37
- package/lib/services/collab/index.js +0 -468
- package/test.js +0 -38
|
@@ -17,105 +17,30 @@
|
|
|
17
17
|
* is strictly forbidden unless prior written permission is obtained
|
|
18
18
|
* from Compro Technologies Pvt. Ltd..
|
|
19
19
|
***************************************************************************/
|
|
20
|
-
|
|
21
|
-
* comproDLS SDK Generic API Caller
|
|
22
|
-
* This module provides generic function(s) to call any comproDLS API.
|
|
23
|
-
* The generic approach for calling API(s) require a prior knowledge of
|
|
24
|
-
* the specific URLs and parameters (as per the API documentation).
|
|
25
|
-
************************************************************/
|
|
26
|
-
var request = require('superagent');
|
|
27
|
-
var q = require('q');
|
|
28
|
-
var format = require("string-template");
|
|
20
|
+
var format = require('string-template');
|
|
29
21
|
|
|
30
|
-
var config = require('../../../config');
|
|
31
|
-
var helpers = require('../../../helpers');
|
|
32
|
-
var errors = require('../errors');
|
|
33
|
-
var DLSError = errors.DLSError;
|
|
34
|
-
var validations = require('./validations');
|
|
35
|
-
|
|
36
|
-
/*********************************
|
|
37
|
-
* Setting up Exports/Public functions
|
|
38
|
-
**********************************/
|
|
39
|
-
exports.genericAPICaller = genericAPICaller;
|
|
40
22
|
exports.constructAPIUrl = constructAPIUrl;
|
|
41
23
|
exports.setupAPIToken = setupAPIToken;
|
|
42
|
-
exports.addClassIdQueryParam = addClassIdQueryParam
|
|
43
|
-
|
|
44
|
-
/*********************************
|
|
45
|
-
* Public Function definitions
|
|
46
|
-
**********************************/
|
|
47
|
-
|
|
48
|
-
//Generic comproDLS API caller
|
|
49
|
-
function genericAPICaller(apiName, method, url, params) {
|
|
50
|
-
var self = this;
|
|
51
|
-
var dfd = q.defer();
|
|
52
|
-
|
|
53
|
-
//Validation
|
|
54
|
-
var err = validations.genericAPICaller(apiName, method, url, params) || helpers.validations.isAuthenticated(self.orgId, self.token);
|
|
55
|
-
if (err) {
|
|
56
|
-
dfd.reject(err);
|
|
57
|
-
} else {
|
|
58
|
-
|
|
59
|
-
//Passed all validations, setup API Url and parameters
|
|
60
|
-
var url = config.DEFAULT_HOSTS[apiName.toUpperCase()] + url;
|
|
61
|
-
|
|
62
|
-
//Setup Delete method for superagent
|
|
63
|
-
if (method === 'DELETE') {
|
|
64
|
-
method = 'DEL';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var requestAPI = request(method, url);
|
|
68
|
-
|
|
69
|
-
//Setting token in Authorization header
|
|
70
|
-
requestAPI = setupAPIToken(requestAPI, self.token);
|
|
71
24
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//Call Specified API
|
|
82
|
-
requestAPI.end(function(err, response) {
|
|
83
|
-
if (err) {
|
|
84
|
-
err = new DLSError(errors.ERROR_TYPES.API_ERROR, err);
|
|
85
|
-
dfd.reject(err);
|
|
86
|
-
} else {
|
|
87
|
-
dfd.resolve(response.body);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return dfd.promise;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/*********************************************************
|
|
95
|
-
* This function constructs the url of comproDLS API.
|
|
96
|
-
* Options: JSON Object having actual values to replace in API URLs
|
|
97
|
-
* Following are valid feilds in options object:
|
|
98
|
-
{
|
|
99
|
-
"orgId" : "",
|
|
100
|
-
"productId" : "",
|
|
101
|
-
"userId" : "",
|
|
102
|
-
"activityId" : "",
|
|
103
|
-
"attemptId" : "",
|
|
104
|
-
"questionId" : ""
|
|
105
|
-
}
|
|
106
|
-
*********************************************************/
|
|
25
|
+
/**
|
|
26
|
+
* This function constructs the url of comproDLS API.
|
|
27
|
+
* @param {String} url - comproDLS API URL with placeholders
|
|
28
|
+
* @param {Object} options - JSON Object having actual values to replace in API URLs
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
107
31
|
function constructAPIUrl(url, options) {
|
|
108
|
-
|
|
32
|
+
return format(url, options);
|
|
109
33
|
};
|
|
110
34
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
35
|
+
/**
|
|
36
|
+
* [Deprecated] This function is no longer needed. Use requestLayer functions instead,
|
|
37
|
+
* as the API token is now automatically handled by requestLayer.
|
|
38
|
+
*
|
|
39
|
+
* This function sets up the API token in the request header.
|
|
40
|
+
* @param {Object} request - The request object to which the token will be added
|
|
41
|
+
* @param {Object} token - The token object containing the access_token
|
|
42
|
+
* @returns {*} The modified request object with the Authorization header set
|
|
43
|
+
*/
|
|
119
44
|
function setupAPIToken(request, token) {
|
|
120
|
-
|
|
121
|
-
};
|
|
45
|
+
return request.set('Authorization', token.access_token);
|
|
46
|
+
};
|
|
@@ -17,113 +17,108 @@
|
|
|
17
17
|
* is strictly forbidden unless prior written permission is obtained
|
|
18
18
|
* from Compro Technologies Pvt. Ltd..
|
|
19
19
|
***************************************************************************/
|
|
20
|
+
|
|
20
21
|
/***********************************************************
|
|
21
22
|
* comproDLS SDK Error Helper Module
|
|
22
23
|
* This module contains helper functions for Error management
|
|
23
24
|
************************************************************/
|
|
24
25
|
|
|
25
|
-
//All possible Error types in SDK
|
|
26
|
+
// All possible Error types in SDK
|
|
26
27
|
var ERROR_TYPES = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
API_ERROR: 'API_ERROR',
|
|
29
|
+
SDK_ERROR: 'SDK_ERROR',
|
|
30
|
+
CHANNEL_SUBSCRIPTION: 'CHANNEL_SUBSCRIPTION',
|
|
31
|
+
UNEXPECTED_ERROR: 'UNEXPECTED_ERROR',
|
|
32
|
+
POLLING_INITIATION: 'POLLING_INITIATION'
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
var ERROR_CATEGORY = {
|
|
33
|
-
|
|
36
|
+
PUSHX: 'PUSHX'
|
|
34
37
|
};
|
|
35
38
|
|
|
36
|
-
|
|
37
39
|
var ERROR_STATUS = {
|
|
38
|
-
|
|
40
|
+
ERROR: 'ERROR'
|
|
39
41
|
};
|
|
40
42
|
|
|
41
|
-
/****************************************************
|
|
42
|
-
* Setting up Exports/Public functions and variables
|
|
43
|
-
*****************************************************/
|
|
44
43
|
exports.DLSError = DLSError;
|
|
45
44
|
exports.PUSHXError = PUSHXError;
|
|
46
45
|
exports.ERROR_TYPES = ERROR_TYPES;
|
|
47
46
|
exports.ERROR_CATEGORY = ERROR_CATEGORY;
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
* Constructor for the DLS error object
|
|
51
|
-
* Parameters:
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Constructor for the DLS error object
|
|
50
|
+
* Parameters:
|
|
51
|
+
* type: Error Type. Possible values are SDK_ERROR and API_ERROR
|
|
52
|
+
* err: JSON Error object. This can be:
|
|
53
|
+
* 1. HTTP Error Object returned by comproDLS APIs (In case of API_ERROR)
|
|
54
|
+
* 2. Custom Error Object(SDK_ERROR or Custom API_ERROR) with following structure
|
|
55
|
+
* {
|
|
56
|
+
* message: 'string',
|
|
57
|
+
* description: 'string'
|
|
58
|
+
* }
|
|
59
|
+
*/
|
|
61
60
|
function DLSError(type, err) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
this.type = type;
|
|
67
|
-
if (type === ERROR_TYPES.API_ERROR) {
|
|
68
|
-
|
|
69
|
-
//Depending on type of error (HTTP response or Custom) deal with different formats of the err object
|
|
70
|
-
var msg, desc;
|
|
71
|
-
if(err.response != undefined) {
|
|
72
|
-
msg = err.response.body.message || err.response.body.dbErrorBody || err.response.body.code;
|
|
73
|
-
desc = err.response.body.dbErrorDescription;
|
|
74
|
-
|
|
75
|
-
// Add swagger errors
|
|
76
|
-
if(err.response.body.results && err.response.body.results.errors) {
|
|
77
|
-
msg = '';
|
|
78
|
-
for(var idx in err.response.body.results.errors) {
|
|
79
|
-
msg += err.response.body.results.errors[idx].message + ' ';
|
|
80
|
-
}
|
|
81
|
-
}
|
|
61
|
+
// We assume only two types of errors: SDK_ERROR (default) or API_ERROR
|
|
62
|
+
this.type = type;
|
|
63
|
+
if (type === ERROR_TYPES.API_ERROR) {
|
|
82
64
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
// Handling error on the basis of type of error (HTTP response or Custom)
|
|
66
|
+
var msg, desc;
|
|
67
|
+
if(err.response != undefined) {
|
|
68
|
+
msg = err.response.body.message || err.response.body.dbErrorBody || err.response.body.code;
|
|
69
|
+
desc = err.response.body.dbErrorDescription;
|
|
87
70
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
71
|
+
// Add swagger errors
|
|
72
|
+
if (err.response.body.results && err.response.body.results.errors) {
|
|
73
|
+
msg = '';
|
|
74
|
+
for (var idx in err.response.body.results.errors) {
|
|
75
|
+
msg += err.response.body.results.errors[idx].message + ' ';
|
|
91
76
|
}
|
|
77
|
+
}
|
|
92
78
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
else if(type === ERROR_TYPES.PUSHX_ERROR) {
|
|
79
|
+
// Add request_id
|
|
80
|
+
if (err.response.body.server) {
|
|
81
|
+
this.server = err.response.body.server;
|
|
82
|
+
}
|
|
98
83
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this.message = err.message ? err.message : "";
|
|
105
|
-
this.description = err.description ? err.description : "";
|
|
106
|
-
delete err.message;
|
|
107
|
-
delete err.description;
|
|
108
|
-
this.data = err;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (type === ERROR_TYPES.API_ERROR || type === ERROR_TYPES.PUSHX_ERROR) {
|
|
112
|
-
this.httpcode = err.status;
|
|
84
|
+
} else {
|
|
85
|
+
msg = err.message ? err.message : '';
|
|
86
|
+
desc = err.description ? err.description : '';
|
|
113
87
|
}
|
|
88
|
+
|
|
89
|
+
//Set the message and description
|
|
90
|
+
this.message = msg;
|
|
91
|
+
this.description = desc;
|
|
92
|
+
}
|
|
93
|
+
else if (type === ERROR_TYPES.PUSHX_ERROR) {
|
|
94
|
+
//Set the message and description
|
|
95
|
+
this.message = err.message;
|
|
96
|
+
this.data = err;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.message = err.message ? err.message : '';
|
|
100
|
+
this.description = err.description ? err.description : '';
|
|
101
|
+
delete err.message;
|
|
102
|
+
delete err.description;
|
|
103
|
+
this.data = err;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (type === ERROR_TYPES.API_ERROR || type === ERROR_TYPES.PUSHX_ERROR) {
|
|
107
|
+
this.httpcode = err.status;
|
|
108
|
+
}
|
|
114
109
|
};
|
|
115
110
|
|
|
116
111
|
function PUSHXError(category, error) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
112
|
+
if (category === ERROR_CATEGORY.PUSHX) {
|
|
113
|
+
this.category = ERROR_CATEGORY.PUSHX;
|
|
114
|
+
this.type = error.type || ERROR_TYPES.CHANNEL_SUBSCRIPTION;
|
|
115
|
+
this.status = ERROR_STATUS.ERROR;
|
|
116
|
+
this.message = error.message;
|
|
117
|
+
this.data = error;
|
|
118
|
+
this.httpcode = (error.errorDetails && error.errorDetails.statusCode) ?
|
|
119
|
+
error.errorDetails.statusCode : 500;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.message = 'PUSHXError called for incorrect category.';
|
|
123
|
+
}
|
|
129
124
|
};
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
var Request = require('superagent');
|
|
22
|
+
var Agent = require('agentkeepalive');
|
|
23
|
+
|
|
24
|
+
var keepaliveAgent = new Agent({
|
|
25
|
+
timeout: 60000,
|
|
26
|
+
freeSocketTimeout: 30000
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Sends an HTTP GET request to the specified URL with query parameters and optional headers.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} url - The endpoint to send the request to.
|
|
33
|
+
* @param {Object} options.params - Query parameters to append to the URL.
|
|
34
|
+
* @param {Object} options.headers - Optional headers including traceid and token.
|
|
35
|
+
*/
|
|
36
|
+
function getRequest(url, options) {
|
|
37
|
+
var params = options.params, headers = options.headers;
|
|
38
|
+
|
|
39
|
+
return new Promise(function (resolve, reject) {
|
|
40
|
+
// Setup request with URL and Params
|
|
41
|
+
var requestAPI = Request.get(url)
|
|
42
|
+
.set('Accept', 'application/json')
|
|
43
|
+
.query(params);
|
|
44
|
+
|
|
45
|
+
// Setting headers in the request.
|
|
46
|
+
if (headers) {
|
|
47
|
+
if (headers.traceid) { requestAPI.set('X-Amzn-Trace-Id', headers.traceid); }
|
|
48
|
+
if (headers.token) { requestAPI.set('Authorization', headers.token.access_token); }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
requestAPI
|
|
52
|
+
.agent(keepaliveAgent)
|
|
53
|
+
.then(function (res) { resolve(res); })
|
|
54
|
+
.catch(function (err) { reject(err); });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sends an HTTP POST request to the specified URL with a JSON body and optional headers.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} url - The endpoint to send the request to.
|
|
62
|
+
* @param {Object} options.params - Payload to be sent in the request body.
|
|
63
|
+
* @param {Object} options.headers - Optional headers including traceid and token.
|
|
64
|
+
*/
|
|
65
|
+
function postRequest(url, options) {
|
|
66
|
+
var params = options.params, headers = options.headers;
|
|
67
|
+
|
|
68
|
+
return new Promise(function (resolve, reject) {
|
|
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(params);
|
|
74
|
+
|
|
75
|
+
// Setting headers in the request.
|
|
76
|
+
if (headers) {
|
|
77
|
+
if (headers.traceid) { requestAPI.set('X-Amzn-Trace-Id', headers.traceid); }
|
|
78
|
+
if (headers.token) { requestAPI.set('Authorization', headers.token.access_token); }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
requestAPI
|
|
82
|
+
.agent(keepaliveAgent)
|
|
83
|
+
.then(function (res) { resolve(res); })
|
|
84
|
+
.catch(function (err) { reject(err); });
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Sends an HTTP PUT request to the specified URL with a JSON body and optional headers.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} url - The endpoint to send the request to.
|
|
92
|
+
* @param {Object} options.params - Payload to be sent in the request body.
|
|
93
|
+
* @param {Object} options.headers - Optional headers including traceid and token.
|
|
94
|
+
*/
|
|
95
|
+
function putRequest(url, options) {
|
|
96
|
+
var params = options.params, headers = options.headers;
|
|
97
|
+
|
|
98
|
+
return new Promise(function (resolve, reject) {
|
|
99
|
+
//Setup request with URL and Params
|
|
100
|
+
var requestAPI = Request.put(url)
|
|
101
|
+
.set('Content-Type', 'application/json')
|
|
102
|
+
.set('Accept', 'application/json')
|
|
103
|
+
.send(params);
|
|
104
|
+
|
|
105
|
+
// Setting headers in the request.
|
|
106
|
+
if (headers) {
|
|
107
|
+
if (headers.traceid) { requestAPI.set('X-Amzn-Trace-Id', headers.traceid); }
|
|
108
|
+
if (headers.token) { requestAPI.set('Authorization', headers.token.access_token); }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
requestAPI
|
|
112
|
+
.agent(keepaliveAgent)
|
|
113
|
+
.then(function (res) { resolve(res); })
|
|
114
|
+
.catch(function (err) { reject(err); });
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Sends an HTTP DELETE request to the specified URL with optional payload and headers.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} url - The endpoint to send the request to.
|
|
122
|
+
* @param {Object} options.params - Payload to be sent in the request body (optional).
|
|
123
|
+
* @param {Object} options.headers - Optional headers including traceid and token.
|
|
124
|
+
*/
|
|
125
|
+
function deleteRequest(url, options) {
|
|
126
|
+
var params = options.params, headers = options.headers;
|
|
127
|
+
|
|
128
|
+
return new Promise(function (resolve, reject) {
|
|
129
|
+
//Setup request with URL and Params
|
|
130
|
+
var requestAPI = Request.delete(url)
|
|
131
|
+
.set('Content-Type', 'application/json')
|
|
132
|
+
.set('Accept', 'application/json')
|
|
133
|
+
.send(params);
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
// Setting headers in the request.
|
|
137
|
+
if (headers) {
|
|
138
|
+
if (headers.traceid) { requestAPI.set('X-Amzn-Trace-Id', headers.traceid); }
|
|
139
|
+
if (headers.token) { requestAPI.set('Authorization', headers.token.access_token); }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
requestAPI
|
|
143
|
+
.agent(keepaliveAgent)
|
|
144
|
+
.then(function (res) { resolve(res); })
|
|
145
|
+
.catch(function (err) { reject(err); });
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
get: getRequest,
|
|
151
|
+
post: postRequest,
|
|
152
|
+
put: putRequest,
|
|
153
|
+
delete: deleteRequest
|
|
154
|
+
};
|
|
@@ -17,85 +17,98 @@
|
|
|
17
17
|
* is strictly forbidden unless prior written permission is obtained
|
|
18
18
|
* from Compro Technologies Pvt. Ltd..
|
|
19
19
|
***************************************************************************/
|
|
20
|
+
|
|
20
21
|
/***********************************************************
|
|
21
22
|
* comproDLS SDK Validator Helper Module
|
|
22
23
|
* This module contains validation helper functions for comproDLS SDK
|
|
23
24
|
************************************************************/
|
|
24
|
-
var validator = require(
|
|
25
|
+
var validator = require('validate.js');
|
|
25
26
|
var errors = require('./errors');
|
|
26
27
|
var DLSError = errors.DLSError;
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
/****************************************************
|
|
30
|
-
* Setting up Exports/Public functions
|
|
31
|
-
*****************************************************/
|
|
32
29
|
exports.validate = validate;
|
|
33
30
|
exports.isAuthenticated = validateIsAuthenticated;
|
|
31
|
+
exports.isAuthenticatedV2 = validateIsAuthenticatedV2;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* This function validates if the SDK instance is authenticated.
|
|
35
|
+
* It checks if the orgId and token are present.
|
|
36
|
+
* @param {String} orgId - Organization ID
|
|
37
|
+
* @param {Object} token - Token object { access_token: 'string' }
|
|
38
|
+
*/
|
|
39
|
+
function validateIsAuthenticatedV2(orgId, token) {
|
|
40
|
+
if (orgId && token) { return; }
|
|
41
|
+
|
|
42
|
+
var errMsg = 'SDK Instance does not have valid orgid or token. ' +
|
|
43
|
+
'Please authenticate using authWithCredentials or authWithToken method.';
|
|
44
|
+
var errObj = { message: errMsg, description: errMsg};
|
|
45
|
+
return new DLSError(errors.ERROR_TYPES.SDK_ERROR, errObj);
|
|
46
|
+
};
|
|
34
47
|
|
|
35
|
-
/*********************************
|
|
36
|
-
* Public Function definitions
|
|
37
|
-
**********************************/
|
|
38
48
|
function validate(options, constraints) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
return undefined;
|
|
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;
|
|
49
56
|
}
|
|
57
|
+
} else {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
50
60
|
};
|
|
51
61
|
|
|
62
|
+
/**
|
|
63
|
+
* This function is deprecated. Please use validateIsAuthenticatedV2 instead.
|
|
64
|
+
*/
|
|
52
65
|
function validateIsAuthenticated(orgId, token) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
var validate_options = {
|
|
67
|
+
'organization': orgId,
|
|
68
|
+
'token': token
|
|
69
|
+
};
|
|
57
70
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
var validate_constraints = {
|
|
72
|
+
'organization': {
|
|
73
|
+
'presence': {
|
|
74
|
+
'message' : '^SDK Instance does not have valid orgid or token. Please authenticate using authWithCredentials or authWithToken method.'
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
'token': {
|
|
78
|
+
'presence': {
|
|
79
|
+
'message' : '^SDK Instance does not have valid orgid or token. Please authenticate using authWithCredentials or authWithToken method.'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
70
83
|
|
|
71
|
-
|
|
84
|
+
return validate(validate_options, validate_constraints);
|
|
72
85
|
};
|
|
73
86
|
|
|
74
87
|
/*********************************
|
|
75
88
|
* Private Function definitions
|
|
76
89
|
**********************************/
|
|
77
90
|
validator.validators.isString = function(value, options) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
if (!validator.isString(value)) {
|
|
92
|
+
return options.message || 'is not a valid string';
|
|
93
|
+
}
|
|
81
94
|
};
|
|
82
95
|
|
|
83
96
|
validator.validators.isObject = function(value, options) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
if (!validator.isObject(value)) {
|
|
98
|
+
return options.message || 'is not a valid object';
|
|
99
|
+
}
|
|
87
100
|
};
|
|
88
101
|
|
|
89
102
|
validator.validators.contains = function(value, options) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
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;
|
|
100
112
|
}
|
|
101
|
-
}
|
|
113
|
+
}
|
|
114
|
+
};
|