forked from EdwinBetanc0urt/gRPC-Access-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
173 lines (161 loc) · 6.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*************************************************************************************
* Product: ADempiere gRPC Dictionary Client *
* Copyright (C) 2012-2018 E.R.P. Consultores y Asociados, C.A. *
* Contributor(s): Yamel Senih [email protected] *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
************************************************************************************/
class Access {
/**
* Constructor, No authentication required
* @param {string} host
* @param {string} version
* @param {string} language
*/
constructor(host, version, language = 'en_US') {
this.host = host;
this.version = version;
this.language = language;
}
/**
* Load gRPC Connection
* @return {Object} Return request for get data
*/
getService() {
const grpc_promise = require('grpc-promise');
const { AccessServicePromiseClient } = require('./src/grpc/proto/access_grpc_web_pb.js');
var requestService = new AccessServicePromiseClient(this.host);
grpc_promise.promisifyAll(requestService);
return requestService;
}
/**
* Get user roles assigned
* @param {string} userName User Name
* @param {string} userPass User Pass
* @return {UserRoles} Roles Assigned to User
*/
requestUserInfo(userName, userPass) {
const { LoginRequest } = require('./src/grpc/proto/access_pb.js');
let request = new LoginRequest();
request.setUsername(userName);
request.setUserpass(userPass);
request.setClientversion(this.version);
request.setLanguage(this.language);
return this.getService().getUserInfo(request);
}
/**
* User Info
* @param {string} sessionUuid Session
* @return {UserInfoValue} User Info Value
*/
requestUserInfoFromSession(sessionUuid) {
const { UserInfoRequest } = require('./src/grpc/proto/access_pb.js');
let request = new UserInfoRequest();
request.setSessionuuid(sessionUuid);
request.setClientversion(this.version);
request.setLanguage(this.language);
return this.getService().getUserInfoFromSession(request);
}
/**
* Make login
* @param {string} userName User Name
* @param {string} userPass User Pass
* @param {string} organizationUuid Organization
* @param {string} language Login Language
* @param {string} warehouseUuid Warehouse
* @return {Session} Session assigned
*/
requestLogin(userName, userPass, roleUuid, organizationUuid = null, language = 'en_US', warehouseUuid = null) {
const { LoginRequest } = require('./src/grpc/proto/access_pb.js');
let request = new LoginRequest();
request.setUsername(userName);
request.setUserpass(userPass);
request.setRoleuuid(roleUuid);
request.setOrganizationuuid(organizationUuid);
request.setLanguage(language);
request.setWarehouseuuid(warehouseUuid);
request.setClientversion(this.version);
return this.getService().runLogin(request);
}
/**
* Make login with Role, Organization and Warehouse as default values
* @param {string} userName User Name
* @param {string} userPass User Pass
* @param {string} language Login Language
* @return {Session} Session assigned
*/
requestLoginDefault(userName, userPass, language = 'en_US') {
const { LoginRequest } = require('./src/grpc/proto/access_pb.js');
let request = new LoginRequest();
request.setUsername(userName);
request.setUserpass(userPass);
request.setLanguage(language);
request.setClientversion(this.version);
return this.getService().runLoginDefault(request);
}
/**
* Logout Session
* @param {string} sessionUuid Session
* @return {Session} Session Logout
*/
requestLogout(sessionUuid) {
const { LogoutRequest } = require('./src/grpc/proto/access_pb.js');
let request = new LogoutRequest();
request.setSessionuuid(sessionUuid);
request.setClientversion(this.version);
return this.getService().runLogout(request);
}
/**
* Get Session
* @param {string} sessionUuid Session
* @return {Session} Session getted
*/
getSession(sessionUuid) {
const { SessionRequest } = require('./src/grpc/proto/access_pb.js');
let request = new SessionRequest();
request.setSessionuuid(sessionUuid);
request.setClientversion(this.version);
return this.getService().getSession(request);
}
/**
* get User Menu
* @param {string} sessionUuid Session
* @return {UserInfoValue} User Info Value
*/
requestUserMenuFromSession(sessionUuid) {
const { UserInfoRequest } = require('./src/grpc/proto/access_pb.js');
let request = new UserInfoRequest();
request.setSessionuuid(sessionUuid);
request.setClientversion(this.version);
request.setLanguage(this.language);
return this.getService().getMenuAndChild(request);
}
/**
* Role Change
* @param {object} attributes Session
* @param {string} attributes.sessionUuid
* @param {string} attributes.roleUuid
* @param {string} attributes.organizationUuid
* @param {string} attributes.warehouseUuid
*/
requestChangeRole(attributes) {
const { ChangeRoleRequest } = require('./src/grpc/proto/access_pb.js');
let request = new ChangeRoleRequest();
request.setSessionuuid(attributes.sessionUuid);
request.setRoleuuid(attributes.roleUuid);
request.setOrganizationuuid(attributes.organizationUuid);
request.setWarehouseuuid(attributes.warehouseUuid);
request.setClientversion(this.version);
request.setLanguage(this.language);
return this.getService().runChangeRole(request);
}
}
module.exports = Access;