zocrmsdkmiblu 0.2.13 → 0.2.14
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/lib/js/ZCRMRestClient.js +8 -3
- package/lib/js/mysql/mysql_util.js +100 -92
- package/package.json +1 -1
package/lib/js/ZCRMRestClient.js
CHANGED
|
@@ -335,10 +335,15 @@ ZCRMRestClient.parseAndConstructObject = function (response) {
|
|
|
335
335
|
|
|
336
336
|
resultObj.refresh_token = body.refresh_token;
|
|
337
337
|
}
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
var expiresMs;
|
|
339
|
+
if (body.expires_in_sec) {
|
|
340
|
+
expiresMs = body.expires_in_sec * 1000;
|
|
341
|
+
} else if (body.expires_in) {
|
|
342
|
+
expiresMs = body.expires_in * 1000;
|
|
343
|
+
} else {
|
|
344
|
+
expiresMs = 3600 * 1000;
|
|
340
345
|
}
|
|
341
|
-
resultObj.expires_in =
|
|
346
|
+
resultObj.expires_in = expiresMs + current_time;
|
|
342
347
|
}
|
|
343
348
|
return resultObj;
|
|
344
349
|
|
|
@@ -2,160 +2,168 @@
|
|
|
2
2
|
var mysql_util = {};
|
|
3
3
|
var mysql = require('mysql');
|
|
4
4
|
|
|
5
|
-
mysql_util.saveOAuthTokens = function(config_obj){
|
|
5
|
+
mysql_util.saveOAuthTokens = function (config_obj) {
|
|
6
6
|
|
|
7
|
-
return new Promise(function(resolve,reject){
|
|
8
|
-
|
|
9
|
-
var con = getConnection();
|
|
7
|
+
return new Promise(function (resolve, reject) {
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
var con = getConnection();
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
var sql = "INSERT INTO oauthtokens (useridentifier, accesstoken,refreshtoken,expirytime) VALUES ('" + config_obj.user_identifier + "','" + config_obj.access_token + "','" + config_obj.refresh_token + "'," + config_obj.expires_in + ")";
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
mysql_util.deleteOAuthTokens().then(function () {
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
throw new Error(err);
|
|
19
|
-
}
|
|
15
|
+
con.connect(function (err) {
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
if (err) {
|
|
18
|
+
throw new Error(err);
|
|
19
|
+
}
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
throw new Error(err);
|
|
25
|
-
con.end();
|
|
26
|
-
}
|
|
21
|
+
con.query(sql, function (err, result) {
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
if (err) {
|
|
24
|
+
throw new Error(err);
|
|
25
|
+
con.end();
|
|
26
|
+
}
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
con.end();
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
resolve();
|
|
31
|
+
|
|
32
|
+
})
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
})
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
mysql_util.getOAuthTokens = function(){
|
|
42
|
+
mysql_util.getOAuthTokens = function () {
|
|
43
43
|
|
|
44
|
-
return new Promise(function(resolve,reject){
|
|
44
|
+
return new Promise(function (resolve, reject) {
|
|
45
45
|
|
|
46
46
|
var con = getConnection();
|
|
47
47
|
|
|
48
48
|
var crmclient = require('../ZCRMRestClient');
|
|
49
|
-
con.connect(function(err){
|
|
49
|
+
con.connect(function (err) {
|
|
50
|
+
|
|
51
|
+
if (err) throw err;
|
|
52
|
+
|
|
53
|
+
var sql = "Select * from oauthtokens where useridentifier = '" + crmclient.getUserIdentifier() + "'";
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
con.query(sql, function (err, result) {
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
if (err) {
|
|
58
|
+
throw new Error(err);
|
|
59
|
+
con.end();
|
|
60
|
+
}
|
|
56
61
|
|
|
57
|
-
if(err) {
|
|
58
|
-
throw new Error(err);
|
|
59
62
|
con.end();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
con.end();
|
|
63
|
-
|
|
64
|
-
if(result != undefined && result.length != 0)
|
|
65
|
-
{
|
|
66
|
-
var modified_result ={};
|
|
67
|
-
modified_result["access_token"] = result[0].accesstoken;
|
|
68
|
-
modified_result["refresh_token"] = result[0].refreshtoken;
|
|
69
|
-
modified_result["expires_in"] = result[0].expirytime;
|
|
70
|
-
modified_result["user_identifier"] = result[0].useridentifier;
|
|
71
|
-
resolve(modified_result);
|
|
72
|
-
}
|
|
73
|
-
resolve(result);
|
|
74
|
-
});
|
|
75
63
|
|
|
76
|
-
|
|
64
|
+
if (result != undefined && result.length != 0) {
|
|
65
|
+
var modified_result = {};
|
|
66
|
+
modified_result["access_token"] = result[0].accesstoken;
|
|
67
|
+
modified_result["refresh_token"] = result[0].refreshtoken;
|
|
68
|
+
modified_result["expires_in"] = result[0].expirytime;
|
|
69
|
+
modified_result["user_identifier"] = result[0].useridentifier;
|
|
70
|
+
resolve(modified_result);
|
|
71
|
+
}
|
|
72
|
+
resolve(result);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
});
|
|
77
76
|
})
|
|
78
|
-
|
|
79
|
-
}
|
|
80
77
|
|
|
81
|
-
|
|
78
|
+
}
|
|
82
79
|
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
mysql_util.updateOAuthTokens = function (config_obj) {
|
|
81
|
+
|
|
82
|
+
return new Promise(function (resolve, reject) {
|
|
83
|
+
if (!config_obj ||
|
|
84
|
+
!config_obj.access_token ||
|
|
85
|
+
config_obj.expires_in === undefined ||
|
|
86
|
+
config_obj.expires_in === null ||
|
|
87
|
+
isNaN(config_obj.expires_in)) {
|
|
88
|
+
return reject(new Error(
|
|
89
|
+
'updateOAuthTokens: config_obj is missing required fields. ' +
|
|
90
|
+
'Got: ' + JSON.stringify(config_obj)
|
|
91
|
+
));
|
|
92
|
+
}
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
var con = getConnection();
|
|
95
|
+
var crmclient = require('../ZCRMRestClient');
|
|
96
|
+
con.connect(function (err) {
|
|
89
97
|
|
|
90
|
-
|
|
98
|
+
if (err) throw err;
|
|
91
99
|
|
|
92
|
-
|
|
100
|
+
var sql = `
|
|
93
101
|
update oauthtokens
|
|
94
102
|
set accesstoken = '${config_obj.access_token}',
|
|
95
103
|
expirytime=${config_obj.expires_in}
|
|
96
104
|
where useridentifier = '${crmclient.getUserIdentifier()}'`;
|
|
97
|
-
|
|
98
|
-
con.query(sql,function(err,result){
|
|
99
|
-
|
|
100
|
-
if(err) {
|
|
101
|
-
throw new Error(err);
|
|
102
|
-
con.end();
|
|
103
|
-
}
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
con.query(sql, function (err, result) {
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
if (err) {
|
|
109
|
+
con.end();
|
|
110
|
+
return reject(err);
|
|
111
|
+
}
|
|
108
112
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
con.end();
|
|
114
|
+
|
|
115
|
+
resolve(result);
|
|
116
|
+
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
});
|
|
112
120
|
}
|
|
113
121
|
|
|
114
|
-
mysql_util.deleteOAuthTokens = function(){
|
|
122
|
+
mysql_util.deleteOAuthTokens = function () {
|
|
115
123
|
|
|
116
|
-
return new Promise(function(resolve,reject){
|
|
124
|
+
return new Promise(function (resolve, reject) {
|
|
117
125
|
|
|
118
126
|
var con = getConnection();
|
|
119
127
|
|
|
120
128
|
var crmclient = require('../ZCRMRestClient');
|
|
121
129
|
|
|
122
|
-
var sql = "delete from oauthtokens where useridentifier='"+crmclient.getUserIdentifier()+"'";
|
|
130
|
+
var sql = "delete from oauthtokens where useridentifier='" + crmclient.getUserIdentifier() + "'";
|
|
123
131
|
|
|
124
|
-
con.connect(function(err){
|
|
132
|
+
con.connect(function (err) {
|
|
125
133
|
|
|
126
|
-
if(err) throw err;
|
|
127
|
-
|
|
128
|
-
con.query(sql,function(err,result){
|
|
134
|
+
if (err) throw err;
|
|
129
135
|
|
|
130
|
-
|
|
131
|
-
throw new Error(err);
|
|
132
|
-
}
|
|
136
|
+
con.query(sql, function (err, result) {
|
|
133
137
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
if (err) {
|
|
139
|
+
throw new Error(err);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
con.end();
|
|
138
143
|
|
|
144
|
+
resolve(result);
|
|
145
|
+
})
|
|
139
146
|
|
|
147
|
+
|
|
148
|
+
})
|
|
140
149
|
})
|
|
141
|
-
})
|
|
142
150
|
|
|
143
151
|
}
|
|
144
152
|
|
|
145
153
|
|
|
146
|
-
function getConnection(){
|
|
154
|
+
function getConnection() {
|
|
147
155
|
|
|
148
156
|
var crmclient = require('../ZCRMRestClient');
|
|
149
157
|
var con = mysql.createConnection({
|
|
150
158
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
host: process.env.MYSQL_IP || "127.0.0.1",
|
|
160
|
+
user: crmclient.getMySQLUserName(),
|
|
161
|
+
password: crmclient.getMYSQLPassword(),
|
|
162
|
+
database: "zohooauth"
|
|
155
163
|
|
|
156
|
-
|
|
164
|
+
});
|
|
157
165
|
|
|
158
|
-
|
|
166
|
+
return con;
|
|
159
167
|
|
|
160
168
|
}
|
|
161
169
|
|