@jibb-open/jssdk 3.5.5
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/.babelrc +31 -0
- package/README.md +3 -0
- package/package.json +72 -0
- package/src/api/admin.js +333 -0
- package/src/api/auth.js +208 -0
- package/src/api/eventbus.js +246 -0
- package/src/api/index.js +26 -0
- package/src/api/meeting.js +421 -0
- package/src/api/recording.js +225 -0
- package/src/api/superadmin.js +84 -0
- package/src/api/user.js +46 -0
- package/src/api/webexbot.js +32 -0
- package/src/api/whiteboard.js +175 -0
- package/src/config.js +12 -0
- package/src/examples/browser/462.jibb.js +1 -0
- package/src/examples/browser/index.html +13 -0
- package/src/examples/browser/jibb.js +2 -0
- package/src/examples/browser/startSession.js +112 -0
- package/src/examples/examples.js +5 -0
- package/src/examples/webexDevicesMacros/cameraPresets/jibb.js +338 -0
- package/src/examples/webexDevicesMacros/simplestExample/jibb.js +212 -0
- package/src/examples/webexDevicesMacros/webexDevice JSSDK/jibb_WebexXapi.js +2 -0
- package/src/examples/webexDevicesMacros/withCameraControl/jibb.js +303 -0
- package/src/index.webex-devices.js +13 -0
- package/src/post-processing.js +39 -0
- package/src/types/exceptions.js +48 -0
- package/src/types/jibb.pb.js +1426 -0
- package/src/types/proto.js +7 -0
- package/src/types/types.js +64 -0
- package/src/utils/cached_variable.js +23 -0
- package/src/utils/future.js +24 -0
- package/src/utils/http/http.axios.js +34 -0
- package/src/utils/http/http.xapi.js +87 -0
- package/src/utils/http/index.js +8 -0
- package/src/utils/index.js +5 -0
- package/src/utils/logger/index.js +11 -0
- package/src/utils/logger/logger.empty.js +25 -0
- package/src/utils/logger/logger.pino.js +15 -0
- package/src/ws/connection_base.js +81 -0
- package/src/ws/eventbus.js +363 -0
- package/src/ws/index.js +15 -0
- package/src/ws/ipsa.js +238 -0
- package/src/ws/meeting.js +170 -0
- package/src/ws/observable_connection.js +84 -0
- package/src/ws/retry_connection.js +82 -0
- package/webpack.config.cjs +144 -0
package/.babelrc
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"webapp": {
|
|
4
|
+
"ignore": ["**/*.xapi.js", "**/*.webex-devices.js"],
|
|
5
|
+
"presets": [
|
|
6
|
+
[
|
|
7
|
+
"@babel/env",
|
|
8
|
+
{
|
|
9
|
+
"targets": {
|
|
10
|
+
"edge": "17",
|
|
11
|
+
"firefox": "60",
|
|
12
|
+
"chrome": "67",
|
|
13
|
+
"safari": "11.1"
|
|
14
|
+
},
|
|
15
|
+
"useBuiltIns": "usage",
|
|
16
|
+
"corejs": "3.6.5"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
],
|
|
20
|
+
|
|
21
|
+
"plugins": [
|
|
22
|
+
[
|
|
23
|
+
"babel-plugin-transform-import-ignore",
|
|
24
|
+
{
|
|
25
|
+
"patterns": [".webex-devices.js", "*xapi*"]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jibb-open/jssdk",
|
|
3
|
+
"version": "3.5.5",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "LOG_LEVEL=error mocha --timeout 10000 ",
|
|
7
|
+
"coverage": "npm run test",
|
|
8
|
+
"build": "BABEL_ENV=webapp babel src --out-dir dist --copy-files --no-copy-ignored",
|
|
9
|
+
"watch": "watch 'npm run build' src",
|
|
10
|
+
"docs": "jsdoc -r ./src/ ./README.md"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/Inkerz/jibb-jssdk.git"
|
|
15
|
+
},
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/Inkerz/jibb-jssdk/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/Inkerz/jibb-jssdk#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^0.24.0",
|
|
24
|
+
"browser-or-node": "^2.0.0",
|
|
25
|
+
"buffer": "^6.0.3",
|
|
26
|
+
"bufferutil": "^4.0.6",
|
|
27
|
+
"core-js": "^3.23.1",
|
|
28
|
+
"dateformat": "^5.0.3",
|
|
29
|
+
"isomorphic-ws": "^4.0.1",
|
|
30
|
+
"jwt-decode": "^3.1.2",
|
|
31
|
+
"path": "^0.12.7",
|
|
32
|
+
"pino": "^7.6.5",
|
|
33
|
+
"pino-pretty": "^7.5.3",
|
|
34
|
+
"protobufjs": "6.11.3",
|
|
35
|
+
"rimraf": "^3.0.2",
|
|
36
|
+
"utf-8-validate": "^5.0.9",
|
|
37
|
+
"ws": "^8.5.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@babel/cli": "^7.17.10",
|
|
41
|
+
"@babel/core": "^7.19.6",
|
|
42
|
+
"@babel/node": "^7.20.0",
|
|
43
|
+
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
|
|
44
|
+
"@babel/plugin-transform-runtime": "^7.18.5",
|
|
45
|
+
"@babel/polyfill": "^7.12.1",
|
|
46
|
+
"@babel/preset-env": "^7.19.4",
|
|
47
|
+
"@babel/runtime": "^7.20.0",
|
|
48
|
+
"babel-loader": "^8.2.5",
|
|
49
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
50
|
+
"babel-plugin-transform-import-ignore": "^1.1.0",
|
|
51
|
+
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
|
|
52
|
+
"chai": "^4.3.6",
|
|
53
|
+
"chai-http": "^4.3.0",
|
|
54
|
+
"chai-spies": "^1.0.0",
|
|
55
|
+
"copy-webpack-plugin": "^10.2.4",
|
|
56
|
+
"core-js": "^3.23.1",
|
|
57
|
+
"dotenv": "^16.0.0",
|
|
58
|
+
"esm": "^3.2.25",
|
|
59
|
+
"file-loader": "^6.2.0",
|
|
60
|
+
"gzip-loader": "^0.0.1",
|
|
61
|
+
"jsdoc": "^4.0.0",
|
|
62
|
+
"mocha": "^9.2.0",
|
|
63
|
+
"null-loader": "^4.0.1",
|
|
64
|
+
"nyc": "^15.1.0",
|
|
65
|
+
"pako": "^2.0.4",
|
|
66
|
+
"raw-loader": "^4.0.2",
|
|
67
|
+
"watch": "^1.0.2",
|
|
68
|
+
"webpack": "^5.74.0",
|
|
69
|
+
"webpack-bundle-analyzer": "^4.6.1",
|
|
70
|
+
"webpack-cli": "^4.9.2"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/api/admin.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import {Config} from '../config.js';
|
|
2
|
+
import {http} from "../utils/http/index.js"
|
|
3
|
+
import {Auth} from "./auth.js"
|
|
4
|
+
import {AccessLevel, UserType} from "../types/types.js"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @module admin
|
|
10
|
+
* This is an experimental API.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const accessLevel = AccessLevel.ADMIN
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*
|
|
19
|
+
* @async
|
|
20
|
+
* @returns {array} - list of Organization
|
|
21
|
+
*/
|
|
22
|
+
export async function getOrganizationList() {
|
|
23
|
+
let headers = {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
Accept: "application/json",
|
|
26
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
27
|
+
}
|
|
28
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/admin/organizations`, headers)
|
|
29
|
+
return response.data.organizations
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @async
|
|
35
|
+
* @param {number} orgId
|
|
36
|
+
* @returns {object}
|
|
37
|
+
*/
|
|
38
|
+
export async function getOrganizationDetails(orgId) {
|
|
39
|
+
if (orgId === "") {
|
|
40
|
+
throw new Error("organization ID can not be empty")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let headers = {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
Accept: "application/json",
|
|
46
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
47
|
+
}
|
|
48
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}`, headers)
|
|
49
|
+
return response.data
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @async
|
|
55
|
+
* @param {number} orgId
|
|
56
|
+
* @param {*} pagination
|
|
57
|
+
* @returns {list}
|
|
58
|
+
*/
|
|
59
|
+
export async function getUserList(orgId, pagination) {
|
|
60
|
+
let headers = {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
Accept: "application/json",
|
|
63
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
64
|
+
}
|
|
65
|
+
if (pagination !== undefined) headers["x-jibb-pagination"] = JSON.stringify(pagination)
|
|
66
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/users`, headers)
|
|
67
|
+
|
|
68
|
+
pagination = response.headers["x-jibb-pagination"]
|
|
69
|
+
pagination = pagination && JSON.parse(pagination)
|
|
70
|
+
return {
|
|
71
|
+
users: response.data.users,
|
|
72
|
+
pagination: pagination,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @async
|
|
79
|
+
* @param {object} param0
|
|
80
|
+
* @param {Number} param0.orgId
|
|
81
|
+
* @param {list} param0.users - list of user object that contain email, first_name, last_name, user_type. user_type is a number from 0-4
|
|
82
|
+
* @returns - http result
|
|
83
|
+
*/
|
|
84
|
+
export async function createUsers({ orgId, users }) {
|
|
85
|
+
let headers = {
|
|
86
|
+
"Content-Type": "application/json",
|
|
87
|
+
Accept: "application/json",
|
|
88
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
89
|
+
}
|
|
90
|
+
let body = {
|
|
91
|
+
users,
|
|
92
|
+
}
|
|
93
|
+
return http.post(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/users`, body, headers)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @async
|
|
100
|
+
* @param {object} param0
|
|
101
|
+
* @param {string} param0.orgId
|
|
102
|
+
* @param {string} param0.email
|
|
103
|
+
* @param {number} param0.userType - UNKNOWN = 0; LIMITED = 1; MEMBER = 2; ADMIN = 3; OWNER = 4;
|
|
104
|
+
* @returns - http result
|
|
105
|
+
*/
|
|
106
|
+
export async function createOrganizationUser({ orgId, email, userType }) {
|
|
107
|
+
let headers = {
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
Accept: "application/json",
|
|
110
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
111
|
+
}
|
|
112
|
+
let body = {
|
|
113
|
+
users: [
|
|
114
|
+
{
|
|
115
|
+
email: email,
|
|
116
|
+
user_type: userType,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
}
|
|
120
|
+
return http.post(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/users`, body, headers)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
* @async
|
|
126
|
+
* @param {object} param0
|
|
127
|
+
* @param {number} param0.orgId
|
|
128
|
+
* @param {number} param0.userId
|
|
129
|
+
* @returns - http result
|
|
130
|
+
*/
|
|
131
|
+
export async function SendUserActivationEmail({ orgId, userIds }) {
|
|
132
|
+
let headers = {
|
|
133
|
+
"Content-Type": "application/json",
|
|
134
|
+
Accept: "application/json",
|
|
135
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
136
|
+
}
|
|
137
|
+
let body = {
|
|
138
|
+
user_ids: userIds,
|
|
139
|
+
}
|
|
140
|
+
return http.post(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/activation/email`, body, headers)
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* @async
|
|
145
|
+
* @param {object} param0
|
|
146
|
+
* @param {number} param0.orgId
|
|
147
|
+
* @param {number} param0.userId
|
|
148
|
+
* @returns - http result
|
|
149
|
+
*/
|
|
150
|
+
export async function deleteOrganizationUser({ orgId, userId }) {
|
|
151
|
+
let headers = {
|
|
152
|
+
"Content-Type": "application/json",
|
|
153
|
+
Accept: "application/json",
|
|
154
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
155
|
+
}
|
|
156
|
+
return http.delete(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/users/${userId}`, headers)
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
*
|
|
160
|
+
* @async
|
|
161
|
+
* @param {object} param0
|
|
162
|
+
* @param {number} param0.orgId
|
|
163
|
+
* @param {number} param0.userId
|
|
164
|
+
* @param {number} param0.userType - UNKNOWN = 0; LIMITED = 1; MEMBER = 2; ADMIN = 3; OWNER = 4;
|
|
165
|
+
* @returns - http result
|
|
166
|
+
*/
|
|
167
|
+
export async function updateUserType({ orgId, userId, userType }) {
|
|
168
|
+
let headers = {
|
|
169
|
+
"Content-Type": "application/json",
|
|
170
|
+
Accept: "application/json",
|
|
171
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
172
|
+
}
|
|
173
|
+
let body = {
|
|
174
|
+
user_type: userType,
|
|
175
|
+
}
|
|
176
|
+
return http.patch(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/users/${userId}`, body, headers)
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
*
|
|
180
|
+
* @async
|
|
181
|
+
* @param {object} param0
|
|
182
|
+
* @param {number} param0.orgId
|
|
183
|
+
* @param {number} param0.userId
|
|
184
|
+
* @returns {object}
|
|
185
|
+
*/
|
|
186
|
+
export async function getOrganizationUserDetails({ orgId, userId }) {
|
|
187
|
+
let headers = {
|
|
188
|
+
"Content-Type": "application/json",
|
|
189
|
+
Accept: "application/json",
|
|
190
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
191
|
+
}
|
|
192
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/users/${userId}`, headers)
|
|
193
|
+
return response.data
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// error code:401 status:Unauthorized should we / what token to use ? , orgId? not sure of the body
|
|
197
|
+
/**
|
|
198
|
+
*
|
|
199
|
+
* @async
|
|
200
|
+
* @param {object} param0
|
|
201
|
+
* @param {number} param0.orgId
|
|
202
|
+
* @param {string} [param0.metadata=]
|
|
203
|
+
* @param {boolean} [param0.autoAddUsers=false]
|
|
204
|
+
* @param {UserType} [param0.defaultUserType=0] - UNKNOWN = 0; LIMITED = 1; MEMBER = 2; ADMIN = 3; OWNER = 4;
|
|
205
|
+
* @param {boolean} [param0.enabled=fales]
|
|
206
|
+
* @returns - http result
|
|
207
|
+
*/
|
|
208
|
+
export async function setSAML({ orgId, metadata, autoAddUsers, defaultUserType, enabled }) {
|
|
209
|
+
if (orgId === "" || orgId === undefined) {
|
|
210
|
+
throw new Error("organization ID can not be empty")
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let headers = {
|
|
214
|
+
"Content-Type": "application/json",
|
|
215
|
+
Accept: "application/json",
|
|
216
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
217
|
+
}
|
|
218
|
+
let body = {
|
|
219
|
+
organization_id: orgId,
|
|
220
|
+
metadata: metadata || "",
|
|
221
|
+
auto_add_users: autoAddUsers !== undefined ? autoAddUsers : false,
|
|
222
|
+
default_user_type: defaultUserType !== undefined ? defaultUserType : UserType.UNKNOWN,
|
|
223
|
+
enabled: enabled || false,
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return http.put(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/saml`, body, headers)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// error code:401 status:Unauthorized should we / what token to use ? , orgId? not sure of the body
|
|
230
|
+
/**
|
|
231
|
+
* @async
|
|
232
|
+
* @param {number} orgId
|
|
233
|
+
* @returns - http result
|
|
234
|
+
*/
|
|
235
|
+
export async function deleteSAML(orgId) {
|
|
236
|
+
let headers = {
|
|
237
|
+
"Content-Type": "application/json",
|
|
238
|
+
Accept: "application/json",
|
|
239
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
240
|
+
}
|
|
241
|
+
return http.delete(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/saml`, headers)
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
* @async
|
|
246
|
+
* @param {number} orgId
|
|
247
|
+
* @returns {object}
|
|
248
|
+
*/
|
|
249
|
+
export async function getSAML(orgId) {
|
|
250
|
+
if (orgId === "") {
|
|
251
|
+
throw new Error("organization ID can not be empty")
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let headers = {
|
|
255
|
+
"Content-Type": "application/json",
|
|
256
|
+
Accept: "application/json",
|
|
257
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
258
|
+
}
|
|
259
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/saml`, headers)
|
|
260
|
+
return response.data
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
*
|
|
264
|
+
* @async
|
|
265
|
+
* @param {number} orgId
|
|
266
|
+
* @returns {object}
|
|
267
|
+
*/
|
|
268
|
+
export async function getDomainList(orgId) {
|
|
269
|
+
let headers = {
|
|
270
|
+
"Content-Type": "application/json",
|
|
271
|
+
Accept: "application/json",
|
|
272
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
273
|
+
}
|
|
274
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/domains`, headers)
|
|
275
|
+
return response.data
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
*
|
|
279
|
+
* @async
|
|
280
|
+
* @param {object} param0
|
|
281
|
+
* @param {object} param0.orgId
|
|
282
|
+
* @param {string} param0.domain
|
|
283
|
+
* @returns {object}
|
|
284
|
+
*/
|
|
285
|
+
export async function createDomain({ orgId, domain }) {
|
|
286
|
+
let headers = {
|
|
287
|
+
"Content-Type": "application/json",
|
|
288
|
+
Accept: "application/json",
|
|
289
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
290
|
+
}
|
|
291
|
+
let body = {
|
|
292
|
+
domain_name: domain,
|
|
293
|
+
}
|
|
294
|
+
let response = await http.post(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/domains`, body, headers)
|
|
295
|
+
return response.data
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
*
|
|
299
|
+
* @async
|
|
300
|
+
* @param {object} param0
|
|
301
|
+
* @param {object} param0.orgId
|
|
302
|
+
* @param {string} param0.domain
|
|
303
|
+
* @returns - http result
|
|
304
|
+
*/
|
|
305
|
+
export async function deleteDomain({ orgId, domainId }) {
|
|
306
|
+
let headers = {
|
|
307
|
+
"Content-Type": "application/json",
|
|
308
|
+
Accept: "application/json",
|
|
309
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
310
|
+
}
|
|
311
|
+
return http.delete(`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/domains/${domainId}`, headers)
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
*
|
|
315
|
+
* @async
|
|
316
|
+
* @param {object} param0
|
|
317
|
+
* @param {object} param0.orgId
|
|
318
|
+
* @param {string} param0.domain
|
|
319
|
+
* @returns {object}
|
|
320
|
+
*/
|
|
321
|
+
export async function verifyDomain({ orgId, domainId }) {
|
|
322
|
+
let headers = {
|
|
323
|
+
"Content-Type": "application/json",
|
|
324
|
+
Accept: "application/json",
|
|
325
|
+
"x-jibb-user-jwt": await Auth.getUserToken({ accessLevel: accessLevel }),
|
|
326
|
+
}
|
|
327
|
+
let response = await http.get(
|
|
328
|
+
`${Config.apiBaseURL}/v1/admin/organizations/${orgId}/domains/${domainId}/verify`,
|
|
329
|
+
headers
|
|
330
|
+
)
|
|
331
|
+
return response.data
|
|
332
|
+
}
|
|
333
|
+
|
package/src/api/auth.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Config } from "../config.js"
|
|
2
|
+
import { logger } from "../utils/logger/index.js"
|
|
3
|
+
import { AccessLevel, UserClaims } from "../types/types.js"
|
|
4
|
+
import { http } from "../utils/http/index.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module auth
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* AuthClass.
|
|
13
|
+
* @class AuthClass
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
class AuthClass {
|
|
18
|
+
#userClaims
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
logger.debug("Creating new Auth instance")
|
|
22
|
+
this.apiKey = undefined
|
|
23
|
+
this.#userClaims = new Map()
|
|
24
|
+
this.getIdToken = undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Manually setting userToken
|
|
29
|
+
* @param {string} token
|
|
30
|
+
* @param {AccessLevel} accessLevel
|
|
31
|
+
*/
|
|
32
|
+
setUserToken(token, accessLevel = AccessLevel.USER) {
|
|
33
|
+
let claims = new UserClaims(token)
|
|
34
|
+
this.#userClaims.set(accessLevel, claims)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* setting Api key
|
|
39
|
+
* @param {string} apiKey
|
|
40
|
+
*/
|
|
41
|
+
setApiKey(apiKey) {
|
|
42
|
+
this.apiKey = apiKey
|
|
43
|
+
this.#userClaims.clear()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async #getUserTokenFromApiKey({ expiry, accessLevel }) {
|
|
47
|
+
let headers = {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
Accept: "application/json",
|
|
50
|
+
}
|
|
51
|
+
let body = {
|
|
52
|
+
api_key: this.apiKey,
|
|
53
|
+
expiry: {
|
|
54
|
+
seconds: expiry,
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
let url
|
|
58
|
+
|
|
59
|
+
switch (accessLevel) {
|
|
60
|
+
case AccessLevel.ADMIN:
|
|
61
|
+
url = `${Config.apiBaseURL}/v1/admin/auth/token`
|
|
62
|
+
break
|
|
63
|
+
case AccessLevel.SUPERADMIN:
|
|
64
|
+
url = `${Config.apiBaseURL}/v1/superadmin/auth/token`
|
|
65
|
+
break
|
|
66
|
+
default:
|
|
67
|
+
url = `${Config.apiBaseURL}/v1/auth/token`
|
|
68
|
+
break
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let response = await http.post(url, body, headers)
|
|
72
|
+
return response.data.token
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async #getUserTokenFromIDToken({ expiry, accessLevel }) {
|
|
76
|
+
let headers = {
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
Accept: "application/json",
|
|
79
|
+
"x-jibb-id-jwt": await this.getIdToken(),
|
|
80
|
+
}
|
|
81
|
+
let body = {
|
|
82
|
+
expiry: {
|
|
83
|
+
seconds: expiry,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
let url
|
|
87
|
+
|
|
88
|
+
switch (accessLevel) {
|
|
89
|
+
case AccessLevel.ADMIN:
|
|
90
|
+
url = `${Config.apiBaseURL}/v1/admin/auth/token`
|
|
91
|
+
break
|
|
92
|
+
case AccessLevel.SUPERADMIN:
|
|
93
|
+
url = `${Config.apiBaseURL}/v1/superadmin/auth/token`
|
|
94
|
+
break
|
|
95
|
+
default:
|
|
96
|
+
url = `${Config.apiBaseURL}/v1/auth/token`
|
|
97
|
+
break
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let response = await http.post(url, body, headers)
|
|
101
|
+
return response.data.token
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @returns {UserClaims}
|
|
107
|
+
*/
|
|
108
|
+
async getUserClaims() {
|
|
109
|
+
await this.getUserToken()
|
|
110
|
+
return this.#userClaims.get(AccessLevel.USER)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @async
|
|
116
|
+
* @param {object} [param0={}]
|
|
117
|
+
* @param {Number} [param0.expiry=3600] - meeting ID.
|
|
118
|
+
* @param {boolean} [param0.refresh=fales] - 1 Read or 2 Write.
|
|
119
|
+
* @param {AccessLevel} [param0.accessLevel=AccessLevel.USER]
|
|
120
|
+
* @returns {string} - user Token.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
async getUserToken({ expiry, refresh, accessLevel } = {}) {
|
|
124
|
+
let claim = undefined
|
|
125
|
+
refresh = refresh || false
|
|
126
|
+
accessLevel = accessLevel || AccessLevel.USER
|
|
127
|
+
expiry = expiry || 3600
|
|
128
|
+
|
|
129
|
+
if (refresh === true) {
|
|
130
|
+
await this.#refreshUserToken({ expiry, accessLevel })
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
claim = this.#userClaims.get(accessLevel)
|
|
134
|
+
if (claim !== undefined && !claim.isExpired()) return claim.token
|
|
135
|
+
|
|
136
|
+
await this.#refreshUserToken({ expiry, accessLevel })
|
|
137
|
+
|
|
138
|
+
claim = this.#userClaims.get(accessLevel)
|
|
139
|
+
if (claim !== undefined && !claim.isExpired()) return claim.token
|
|
140
|
+
|
|
141
|
+
throw new Error("could not create user token")
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async #refreshUserToken({ expiry, accessLevel }) {
|
|
145
|
+
if (this.apiKey) {
|
|
146
|
+
let token = await this.#getUserTokenFromApiKey({ expiry, accessLevel })
|
|
147
|
+
this.setUserToken(token, accessLevel)
|
|
148
|
+
return token
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
let token = await this.#getUserTokenFromIDToken({ expiry, accessLevel })
|
|
153
|
+
this.setUserToken(token, accessLevel)
|
|
154
|
+
return token
|
|
155
|
+
} catch (error) {
|
|
156
|
+
logger.error(error)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* clear user.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
logout() {
|
|
165
|
+
this.#userClaims.clear()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* Generate a new API Key, old API KEY will be discareded
|
|
171
|
+
* It require a userToken to be set.
|
|
172
|
+
* @returns {string} api key
|
|
173
|
+
*/
|
|
174
|
+
async generateAPIKey() {
|
|
175
|
+
let headers = {
|
|
176
|
+
"Content-Type": "application/json",
|
|
177
|
+
Accept: "application/json",
|
|
178
|
+
"x-jibb-user-jwt": await this.getUserToken(),
|
|
179
|
+
}
|
|
180
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/auth/apikey`, headers)
|
|
181
|
+
return response.data.apiKey
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
*
|
|
186
|
+
* Generating a one time password.
|
|
187
|
+
* It require a IdToken to be set.
|
|
188
|
+
* @async
|
|
189
|
+
* @returns {string} - Custom Password.
|
|
190
|
+
*/
|
|
191
|
+
async generateCustomAuthPassword() {
|
|
192
|
+
let headers = {
|
|
193
|
+
"Content-Type": "application/json",
|
|
194
|
+
Accept: "application/json",
|
|
195
|
+
"x-jibb-id-jwt": await this.getIdToken(),
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
let response = await http.get(`${Config.apiBaseURL}/v1/auth/custom`, headers)
|
|
199
|
+
return response.data.password
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Expotred instance of AuthClass.
|
|
205
|
+
* @type {AuthClass}
|
|
206
|
+
*/
|
|
207
|
+
let Auth = new AuthClass()
|
|
208
|
+
export { Auth }
|