@webex/test-users 3.0.0-beta.4 → 3.0.0-beta.400
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 +3 -3
- package/dist/index.js +91 -76
- package/dist/index.js.map +1 -1
- package/dist/whistler.js +32 -39
- package/dist/whistler.js.map +1 -1
- package/package.json +4 -4
- package/src/index.js +123 -52
- package/src/whistler.js +75 -59
- package/test/integration/spec/index.js +76 -64
- package/test/integration/spec/whistler.js +4 -5
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ npm install --save @webex/test-users
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
_Note: This package is NODE only, not for browser usage_
|
|
25
25
|
|
|
26
26
|
With the test users library, you can create and remove Webex test users:
|
|
27
27
|
|
|
@@ -32,7 +32,7 @@ createTestUser({displayName: 'Test User'}).then((myTestUser) => {
|
|
|
32
32
|
// Do something amazing with myTestUser
|
|
33
33
|
|
|
34
34
|
// When done, remove the test user
|
|
35
|
-
removeTestUser(myTestUser)
|
|
35
|
+
removeTestUser(myTestUser);
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -68,7 +68,7 @@ createTestUser({whistler: true}).then((myTestUser) => {
|
|
|
68
68
|
// Do something amazing with myTestUser
|
|
69
69
|
|
|
70
70
|
// When done, remove the test user
|
|
71
|
-
removeTestUser(myTestUser)
|
|
71
|
+
removeTestUser(myTestUser);
|
|
72
72
|
});
|
|
73
73
|
```
|
|
74
74
|
|
package/dist/index.js
CHANGED
|
@@ -1,64 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _typeof = require("@babel/runtime-corejs2/helpers/typeof");
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
8
|
-
|
|
4
|
+
var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
5
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
9
6
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
10
|
-
|
|
7
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
8
|
+
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
9
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
10
|
+
var _WeakMap = require("@babel/runtime-corejs2/core-js/weak-map");
|
|
11
11
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
12
|
-
|
|
13
12
|
_Object$defineProperty(exports, "__esModule", {
|
|
14
13
|
value: true
|
|
15
14
|
});
|
|
16
|
-
|
|
17
15
|
exports.createTestUser = createTestUser;
|
|
18
|
-
|
|
19
16
|
_Object$defineProperty(exports, "createWhistlerTestUser", {
|
|
20
17
|
enumerable: true,
|
|
21
18
|
get: function get() {
|
|
22
19
|
return _whistler.default;
|
|
23
20
|
}
|
|
24
21
|
});
|
|
25
|
-
|
|
26
22
|
exports.loginTestUser = loginTestUser;
|
|
27
23
|
exports.removeTestUser = removeTestUser;
|
|
28
|
-
|
|
29
24
|
_Object$defineProperty(exports, "removeWhistlerTestUser", {
|
|
30
25
|
enumerable: true,
|
|
31
26
|
get: function get() {
|
|
32
27
|
return _whistler.removeTestUser;
|
|
33
28
|
}
|
|
34
29
|
});
|
|
35
|
-
|
|
30
|
+
exports.setPreferredSite = setPreferredSite;
|
|
36
31
|
var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
|
|
37
|
-
|
|
38
32
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
39
|
-
|
|
40
|
-
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
41
|
-
|
|
33
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
42
34
|
var _defaultsDeep2 = _interopRequireDefault(require("lodash/defaultsDeep"));
|
|
43
|
-
|
|
44
35
|
var _assert = _interopRequireDefault(require("assert"));
|
|
45
|
-
|
|
46
36
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
47
|
-
|
|
48
37
|
var _btoa = _interopRequireDefault(require("btoa"));
|
|
49
|
-
|
|
50
38
|
var _nodeRandomName = _interopRequireDefault(require("node-random-name"));
|
|
51
|
-
|
|
52
39
|
var _httpCore = require("@webex/http-core");
|
|
53
|
-
|
|
54
40
|
var _whistler = _interopRequireWildcard(require("./whistler"));
|
|
55
|
-
|
|
56
41
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
57
|
-
|
|
58
42
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
59
|
-
|
|
43
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
44
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
60
45
|
var BASE_PATH_SECURE = '/users/test_users_s';
|
|
61
46
|
var BASE_PATH = '/users/test_users';
|
|
47
|
+
|
|
62
48
|
/**
|
|
63
49
|
* Computes `expires` and `refresh_token_expires` from `expires_in` and
|
|
64
50
|
* `refresh_token_expires_in` and creates an `authorization` string.
|
|
@@ -66,27 +52,22 @@ var BASE_PATH = '/users/test_users';
|
|
|
66
52
|
* @private
|
|
67
53
|
* @returns {Object}
|
|
68
54
|
*/
|
|
69
|
-
|
|
70
55
|
function fixToken(token) {
|
|
71
56
|
var now = (0, _now.default)();
|
|
72
|
-
|
|
73
57
|
if (token.expires_in && !token.expires) {
|
|
74
58
|
token.expires = now + token.expires_in * 1000;
|
|
75
59
|
}
|
|
76
|
-
|
|
77
60
|
if (token.refresh_token_expires_in && !token.refresh_token_expires) {
|
|
78
61
|
/* eslint camelcase: [0] */
|
|
79
62
|
token.refresh_token_expires = now + token.refresh_token_expires_in * 1000;
|
|
80
63
|
}
|
|
81
|
-
|
|
82
64
|
if (token.token_type && token.access_token) {
|
|
83
65
|
token.authorization = "".concat(token.token_type, " ").concat(token.access_token);
|
|
84
66
|
}
|
|
85
|
-
|
|
86
67
|
return token;
|
|
87
68
|
}
|
|
88
|
-
|
|
89
69
|
var clientToken;
|
|
70
|
+
|
|
90
71
|
/**
|
|
91
72
|
* Fetches credentials to talk to the test_users_s endpoint
|
|
92
73
|
*
|
|
@@ -98,16 +79,13 @@ var clientToken;
|
|
|
98
79
|
* @private
|
|
99
80
|
* @returns {String}
|
|
100
81
|
*/
|
|
101
|
-
|
|
102
82
|
function getClientCredentials(_ref) {
|
|
103
83
|
var clientId = _ref.clientId,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
84
|
+
clientSecret = _ref.clientSecret,
|
|
85
|
+
idbrokerUrl = _ref.idbrokerUrl;
|
|
107
86
|
if (clientToken) {
|
|
108
87
|
return _promise.default.resolve(clientToken);
|
|
109
88
|
}
|
|
110
|
-
|
|
111
89
|
return (0, _httpCore.request)({
|
|
112
90
|
method: 'POST',
|
|
113
91
|
uri: "".concat(idbrokerUrl, "/idb/oauth2/v1/access_token"),
|
|
@@ -132,6 +110,7 @@ function getClientCredentials(_ref) {
|
|
|
132
110
|
return clientToken;
|
|
133
111
|
});
|
|
134
112
|
}
|
|
113
|
+
|
|
135
114
|
/**
|
|
136
115
|
* Makes a request authorized with client credentials
|
|
137
116
|
* @param {Object} options
|
|
@@ -142,8 +121,6 @@ function getClientCredentials(_ref) {
|
|
|
142
121
|
* @private
|
|
143
122
|
* @returns {Promise<HttpResponseObject>}
|
|
144
123
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
124
|
function requestWithAuth(options) {
|
|
148
125
|
return getClientCredentials(options.body).then(function (authorization) {
|
|
149
126
|
options.headers = options.headers || {};
|
|
@@ -151,6 +128,7 @@ function requestWithAuth(options) {
|
|
|
151
128
|
return (0, _httpCore.request)(options);
|
|
152
129
|
});
|
|
153
130
|
}
|
|
131
|
+
|
|
154
132
|
/**
|
|
155
133
|
* @typedef {Object} AccessTokenObject
|
|
156
134
|
* @property {string} token.access_token
|
|
@@ -178,61 +156,58 @@ function requestWithAuth(options) {
|
|
|
178
156
|
* @property {string} [roles] defaults to []
|
|
179
157
|
* @property {string} [scope] defaults to WEBEX_SCOPE
|
|
180
158
|
* @property {string} [type] used to create a machine
|
|
159
|
+
* @property {boolean} [forceCreate] force creates the user, to be used in conjunction with ensureExistsInWebexSites
|
|
160
|
+
* @property {boolean} [ensureExistsInWebexSites] syncs the user in provided webexSites (syncInWebexSites)
|
|
161
|
+
* @property {Array.<string>} [syncInWebexSites] used to define in which sites account should be synced
|
|
162
|
+
* @property {string} [orgAdminAuthorization] bearer token of org admin to use syncInWebexSites
|
|
181
163
|
*/
|
|
182
164
|
|
|
183
165
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
166
|
+
* @typedef {Object} TestUserObject
|
|
167
|
+
* @property {string} password
|
|
168
|
+
* @property {string} emailAddress
|
|
169
|
+
* @property {string} displayName
|
|
170
|
+
* @property {string} id
|
|
171
|
+
* @property {string} userName
|
|
172
|
+
* @property {string} email
|
|
173
|
+
* @property {string} name
|
|
174
|
+
* @property {string} givenName
|
|
175
|
+
* @property {string} type
|
|
176
|
+
* @property {Array.<string>} entitlements
|
|
177
|
+
* @property {string} orgId
|
|
178
|
+
* @property {AccessTokenObject} token
|
|
179
|
+
*/
|
|
198
180
|
|
|
199
181
|
/**
|
|
200
182
|
* Creates a test user
|
|
201
183
|
* @param {CreateUserOptions} options
|
|
202
184
|
* @returns {Promise.<TestUserObject>}
|
|
203
185
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
186
|
function createTestUser() {
|
|
207
187
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
208
188
|
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
209
189
|
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
210
190
|
var idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;
|
|
211
191
|
var cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
212
|
-
|
|
213
192
|
if (!clientId) {
|
|
214
193
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
215
194
|
}
|
|
216
|
-
|
|
217
195
|
if (!clientSecret) {
|
|
218
196
|
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
219
197
|
}
|
|
220
|
-
|
|
221
198
|
if (!idbrokerUrl) {
|
|
222
199
|
throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');
|
|
223
200
|
}
|
|
224
|
-
|
|
225
201
|
if (!cigServiceUrl) {
|
|
226
202
|
throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');
|
|
227
203
|
}
|
|
228
|
-
|
|
229
204
|
var body = {
|
|
230
205
|
authCodeOnly: options.authCodeOnly,
|
|
231
206
|
clientId: clientId,
|
|
232
207
|
clientSecret: clientSecret,
|
|
233
208
|
displayName: options.displayName || (0, _nodeRandomName.default)(),
|
|
234
209
|
emailTemplate: options.emailAddress,
|
|
235
|
-
entitlements: options.entitlements || ['spark', 'squaredCallInitiation', 'squaredRoomModeration', 'squaredInviter', 'webExSquared'],
|
|
210
|
+
entitlements: options.entitlements || ['spark', 'squaredCallInitiation', 'squaredRoomModeration', 'squaredInviter', 'webExSquared', 'basicMessage'],
|
|
236
211
|
idbrokerUrl: idbrokerUrl,
|
|
237
212
|
machineType: options.machineType,
|
|
238
213
|
orgId: options.orgId,
|
|
@@ -240,7 +215,11 @@ function createTestUser() {
|
|
|
240
215
|
password: options.password || "".concat(_uuid.default.v4(), "zAY1*"),
|
|
241
216
|
roles: options.roles || [],
|
|
242
217
|
scopes: options.scope || process.env.WEBEX_SCOPE,
|
|
243
|
-
type: options.type
|
|
218
|
+
type: options.type,
|
|
219
|
+
forceCreate: options.forceCreate || false,
|
|
220
|
+
ensureExistsInWebexSites: options.ensureExistsInWebexSites || false,
|
|
221
|
+
syncInWebexSites: options.syncInWebexSites,
|
|
222
|
+
orgAdminAuthorization: options.orgAdminAuthorization
|
|
244
223
|
};
|
|
245
224
|
return requestWithAuth({
|
|
246
225
|
method: 'POST',
|
|
@@ -248,15 +227,16 @@ function createTestUser() {
|
|
|
248
227
|
json: true,
|
|
249
228
|
body: body
|
|
250
229
|
}).then(function (res) {
|
|
251
|
-
return (
|
|
230
|
+
return _objectSpread(_objectSpread({
|
|
252
231
|
password: body.password,
|
|
253
232
|
emailAddress: res.body.user.email,
|
|
254
233
|
displayName: res.body.user.name
|
|
255
|
-
}, res.body.user, {
|
|
234
|
+
}, res.body.user), {}, {
|
|
256
235
|
token: fixToken(res.body.token)
|
|
257
236
|
});
|
|
258
237
|
});
|
|
259
238
|
}
|
|
239
|
+
|
|
260
240
|
/**
|
|
261
241
|
* Exchanges a user name/password for an access token
|
|
262
242
|
* @param {Object} options
|
|
@@ -268,25 +248,19 @@ function createTestUser() {
|
|
|
268
248
|
* @param {string} options.cigServiceUrl
|
|
269
249
|
* @returns {Promise.<AccessTokenObject>}
|
|
270
250
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
251
|
function loginTestUser(options) {
|
|
274
252
|
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
275
253
|
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
276
254
|
var cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
277
|
-
|
|
278
255
|
if (!clientId) {
|
|
279
256
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
280
257
|
}
|
|
281
|
-
|
|
282
258
|
if (!clientSecret) {
|
|
283
259
|
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
284
260
|
}
|
|
285
|
-
|
|
286
261
|
if (!cigServiceUrl) {
|
|
287
262
|
throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');
|
|
288
263
|
}
|
|
289
|
-
|
|
290
264
|
return (0, _httpCore.request)({
|
|
291
265
|
method: 'POST',
|
|
292
266
|
uri: "".concat(cigServiceUrl).concat(BASE_PATH, "/login"),
|
|
@@ -299,6 +273,7 @@ function loginTestUser(options) {
|
|
|
299
273
|
return fixToken(res.body);
|
|
300
274
|
});
|
|
301
275
|
}
|
|
276
|
+
|
|
302
277
|
/**
|
|
303
278
|
* Removes a test user
|
|
304
279
|
* @param {Object} options
|
|
@@ -309,27 +284,21 @@ function loginTestUser(options) {
|
|
|
309
284
|
* @param {string} [options.token.refresh_token]
|
|
310
285
|
* @returns {Promise}
|
|
311
286
|
*/
|
|
312
|
-
|
|
313
|
-
|
|
314
287
|
function removeTestUser() {
|
|
315
288
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
316
289
|
var cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
317
|
-
|
|
318
290
|
if (!cigServiceUrl) {
|
|
319
291
|
throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');
|
|
320
292
|
}
|
|
321
|
-
|
|
322
293
|
if (!options.id) {
|
|
323
294
|
return _promise.default.reject(new Error('options.id is required'));
|
|
324
295
|
}
|
|
325
|
-
|
|
326
296
|
if (!options.token) {
|
|
327
297
|
return loginTestUser(options).then(function (token) {
|
|
328
298
|
options.token = token;
|
|
329
299
|
return removeTestUser(options);
|
|
330
300
|
});
|
|
331
301
|
}
|
|
332
|
-
|
|
333
302
|
(0, _assert.default)(options.token.authorization, 'options.token.authorization must be defined');
|
|
334
303
|
return (0, _httpCore.request)({
|
|
335
304
|
method: 'POST',
|
|
@@ -343,9 +312,55 @@ function removeTestUser() {
|
|
|
343
312
|
refresh_token: options.token.refresh_token,
|
|
344
313
|
user_type: options.userType || 'PERSON'
|
|
345
314
|
/* eslint-enable camelcase */
|
|
346
|
-
|
|
347
315
|
},
|
|
316
|
+
|
|
348
317
|
uri: "".concat(cigServiceUrl).concat(BASE_PATH, "/delete")
|
|
349
318
|
});
|
|
350
319
|
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Sets the preferredWebexSite for the provided user
|
|
323
|
+
*
|
|
324
|
+
* This method should be used to ensure a created test user has the right webex site set.
|
|
325
|
+
*
|
|
326
|
+
* @param {Object} options
|
|
327
|
+
* @param {string} options.userId user id to set site
|
|
328
|
+
* @param {string} options.preferredSite new preferred webexsite
|
|
329
|
+
* @param {string} options.orgId orgId of the site
|
|
330
|
+
* @param {string} options.identityServiceUrl url of identity service
|
|
331
|
+
* @param {string} options.authorization
|
|
332
|
+
* @param {string} options.clientId
|
|
333
|
+
* @param {string} options.clientSecret
|
|
334
|
+
* @returns {Promise}
|
|
335
|
+
*/
|
|
336
|
+
function setPreferredSite() {
|
|
337
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
338
|
+
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
339
|
+
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
340
|
+
if (!clientId) {
|
|
341
|
+
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
342
|
+
}
|
|
343
|
+
if (!clientSecret) {
|
|
344
|
+
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/* eslint-disable no-useless-escape */
|
|
348
|
+
var body = {
|
|
349
|
+
schemas: ['urn:scim:schemas:core:1.0', 'urn:scim:schemas:extension:cisco:commonidentity:1.0'],
|
|
350
|
+
userPreferences: [{
|
|
351
|
+
value: "\"preferredWebExSite\":\"".concat(options.preferredSite, "\"")
|
|
352
|
+
}]
|
|
353
|
+
};
|
|
354
|
+
/* eslint-enable no-useless-escape */
|
|
355
|
+
|
|
356
|
+
return (0, _httpCore.request)({
|
|
357
|
+
method: 'PATCH',
|
|
358
|
+
headers: {
|
|
359
|
+
authorization: options.authorization
|
|
360
|
+
},
|
|
361
|
+
uri: "".concat(options.identityServiceUrl, "/identity/scim/").concat(options.orgId, "/v1/Users/").concat(options.userId),
|
|
362
|
+
json: true,
|
|
363
|
+
body: body
|
|
364
|
+
});
|
|
365
|
+
}
|
|
351
366
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BASE_PATH_SECURE","BASE_PATH","fixToken","token","now","expires_in","expires","refresh_token_expires_in","refresh_token_expires","token_type","access_token","authorization","clientToken","getClientCredentials","clientId","clientSecret","idbrokerUrl","resolve","request","method","uri","json","form","grant_type","scope","client_id","client_secret","headers","btoa","then","res","body","requestWithAuth","options","createTestUser","process","env","WEBEX_CLIENT_ID","WEBEX_CLIENT_SECRET","IDBROKER_BASE_URL","cigServiceUrl","WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL","WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL","Error","authCodeOnly","displayName","randomName","emailTemplate","emailAddress","entitlements","machineType","orgId","password","uuid","v4","roles","scopes","WEBEX_SCOPE","type","user","email","name","loginTestUser","removeTestUser","id","reject","assert","user_id","refresh_token","user_type","userType"],"sources":["index.js"],"sourcesContent":["import assert from 'assert';\n\nimport uuid from 'uuid';\nimport btoa from 'btoa';\nimport _ from 'lodash';\nimport randomName from 'node-random-name';\nimport {request} from '@webex/http-core';\n\nconst BASE_PATH_SECURE = '/users/test_users_s';\nconst BASE_PATH = '/users/test_users';\n\n/**\n * Computes `expires` and `refresh_token_expires` from `expires_in` and\n * `refresh_token_expires_in` and creates an `authorization` string.\n * @param {Object} token\n * @private\n * @returns {Object}\n */\nfunction fixToken(token) {\n const now = Date.now();\n\n if (token.expires_in && !token.expires) {\n token.expires = now + token.expires_in * 1000;\n }\n\n if (token.refresh_token_expires_in && !token.refresh_token_expires) {\n /* eslint camelcase: [0] */\n token.refresh_token_expires = now + token.refresh_token_expires_in * 1000;\n }\n\n if (token.token_type && token.access_token) {\n token.authorization = `${token.token_type} ${token.access_token}`;\n }\n\n return token;\n}\n\nlet clientToken;\n\n/**\n * Fetches credentials to talk to the test_users_s endpoint\n *\n * Caches result in `clientToken` variable for multiple runs\n * @param {Object} options\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.idbrokerUrl\n * @private\n * @returns {String}\n */\nfunction getClientCredentials({clientId, clientSecret, idbrokerUrl}) {\n if (clientToken) {\n return Promise.resolve(clientToken);\n }\n\n return request({\n method: 'POST',\n uri: `${idbrokerUrl}/idb/oauth2/v1/access_token`,\n json: true,\n form: {\n grant_type: 'client_credentials',\n scope: 'Identity:SCIM webexsquare:get_conversation',\n client_id: clientId,\n client_secret: clientSecret\n },\n headers: {\n // Note: we can't request's auth hash here because this endpoint expects\n // us to send the auth header *without including \"Basic \"* before the\n // token string\n authorization: btoa(`${clientId}:${clientSecret}`)\n }\n })\n .then((res) => {\n const token = fixToken(res.body);\n\n return `${token.token_type} ${token.access_token}`;\n })\n .then((token) => {\n clientToken = token;\n\n return clientToken;\n });\n}\n\n/**\n * Makes a request authorized with client credentials\n * @param {Object} options\n * @param {Object} options.body\n * @param {string} options.body.clientId\n * @param {string} options.body.clientSecret\n * @param {string} options.body.idbrokerUrl\n * @private\n * @returns {Promise<HttpResponseObject>}\n */\nfunction requestWithAuth(options) {\n return getClientCredentials(options.body)\n .then((authorization) => {\n options.headers = options.headers || {};\n options.headers.authorization = authorization;\n\n return request(options);\n });\n}\n\n/**\n * @typedef {Object} AccessTokenObject\n * @property {string} token.access_token\n * @property {Number} token.expires_in\n * @property {string} token.token_type\n * @property {string} token.refresh_token\n * @property {Number} token.refresh_token_expires_in\n * @property {string} token.expires\n * @property {string} token.refresh_token_expires\n */\n\n/**\n * @typedef {Object} CreateUserOptions\n * @property {boolean} [authCodeOnly] generates auth_code\n * @param {string} [clientId] defaults to WEBEX_CLIENT_ID\n * @param {string} [clientSecret] defaults to WEBEX_CLIENT_SECRET\n * @param {string} [cigServiceUrl] defaults to WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL\n * @property {string} [displayName]\n * @property {string} [emailAddress]\n * @property {Array.<string>} [entitlements]\n * @param {string} [idbrokerUrl] defaults to IDBROKER_BASE_URL\n * @property {string} [machineType] used when creating a machine user/device\n * @property {string} [orgId] organization ID to create the user under\n * @property {string} [password] defaults to a random password\n * @property {string} [roles] defaults to []\n * @property {string} [scope] defaults to WEBEX_SCOPE\n * @property {string} [type] used to create a machine\n */\n\n/**\n * @typedef {Object} TestUserObject\n * @property {string} password\n * @property {string} emailAddress\n * @property {string} displayName\n * @property {string} id\n * @property {string} userName\n * @property {string} email\n * @property {string} name\n * @property {string} givenName\n * @property {string} type\n * @property {Array.<string>} entitlements\n * @property {string} orgId\n * @property {AccessTokenObject} token\n */\n\n/**\n * Creates a test user\n * @param {CreateUserOptions} options\n * @returns {Promise.<TestUserObject>}\n */\nexport function createTestUser(options = {}) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;\n const cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!idbrokerUrl) {\n throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');\n }\n\n const body = {\n authCodeOnly: options.authCodeOnly,\n clientId,\n clientSecret,\n displayName: options.displayName || randomName(),\n emailTemplate: options.emailAddress,\n entitlements: options.entitlements || [\n 'spark',\n 'squaredCallInitiation',\n 'squaredRoomModeration',\n 'squaredInviter',\n 'webExSquared'\n ],\n idbrokerUrl,\n machineType: options.machineType,\n orgId: options.orgId,\n // The five characters on the end are to hit all the password requirements\n password: options.password || `${uuid.v4()}zAY1*`,\n roles: options.roles || [],\n scopes: options.scope || process.env.WEBEX_SCOPE,\n type: options.type\n };\n\n return requestWithAuth({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH_SECURE}`,\n json: true,\n body\n })\n .then((res) => Object.assign({\n password: body.password,\n emailAddress: res.body.user.email,\n displayName: res.body.user.name\n }, res.body.user, {token: fixToken(res.body.token)}));\n}\n\n/**\n * Exchanges a user name/password for an access token\n * @param {Object} options\n * @param {string} options.id\n * @param {string} options.email\n * @param {string} options.password\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.cigServiceUrl\n * @returns {Promise.<AccessTokenObject>}\n */\nexport function loginTestUser(options) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');\n }\n\n return request({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH}/login`,\n json: true,\n body: _.defaultsDeep(options, {\n clientId,\n clientSecret\n })\n })\n .then((res) => fixToken(res.body));\n}\n\n/**\n * Removes a test user\n * @param {Object} options\n * @param {string} options.id user id to remove\n * @param {string} options.cigServiceUrl\n * @param {Object} options.token\n * @param {string} options.token.authorization\n * @param {string} [options.token.refresh_token]\n * @returns {Promise}\n */\nexport function removeTestUser(options = {}) {\n const cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!cigServiceUrl) {\n throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');\n }\n\n if (!options.id) {\n return Promise.reject(new Error('options.id is required'));\n }\n\n if (!options.token) {\n return loginTestUser(options)\n .then((token) => {\n options.token = token;\n\n return removeTestUser(options);\n });\n }\n\n assert(options.token.authorization, 'options.token.authorization must be defined');\n\n return request({\n method: 'POST',\n json: true,\n headers: {\n authorization: options.token.authorization\n },\n body: {\n /* eslint-disable camelcase */\n user_id: options.id,\n refresh_token: options.token.refresh_token,\n user_type: options.userType || 'PERSON'\n /* eslint-enable camelcase */\n },\n uri: `${cigServiceUrl}${BASE_PATH}/delete`\n });\n}\n\nexport {\n default as createWhistlerTestUser,\n removeTestUser as removeWhistlerTestUser\n} from './whistler';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AAEA;;AACA;;AAuSA;;;;;;AArSA,IAAMA,gBAAgB,GAAG,qBAAzB;AACA,IAAMC,SAAS,GAAG,mBAAlB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,QAAT,CAAkBC,KAAlB,EAAyB;EACvB,IAAMC,GAAG,GAAG,mBAAZ;;EAEA,IAAID,KAAK,CAACE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C9B,KAAR,CAAciE,aAHzB;MAIJC,SAAS,EAAEpC,OAAO,CAACqC,QAAR,IAAoB;MAC/B;;IALI,CANO;IAablD,GAAG,YAAKoB,aAAL,SAAqBvC,SAArB;EAbU,CAAR,CAAP;AAeD"}
|
|
1
|
+
{"version":3,"names":["BASE_PATH_SECURE","BASE_PATH","fixToken","token","now","expires_in","expires","refresh_token_expires_in","refresh_token_expires","token_type","access_token","authorization","clientToken","getClientCredentials","clientId","clientSecret","idbrokerUrl","resolve","request","method","uri","json","form","grant_type","scope","client_id","client_secret","headers","btoa","then","res","body","requestWithAuth","options","createTestUser","process","env","WEBEX_CLIENT_ID","WEBEX_CLIENT_SECRET","IDBROKER_BASE_URL","cigServiceUrl","WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL","WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL","Error","authCodeOnly","displayName","randomName","emailTemplate","emailAddress","entitlements","machineType","orgId","password","uuid","v4","roles","scopes","WEBEX_SCOPE","type","forceCreate","ensureExistsInWebexSites","syncInWebexSites","orgAdminAuthorization","user","email","name","loginTestUser","removeTestUser","id","reject","assert","user_id","refresh_token","user_type","userType","setPreferredSite","schemas","userPreferences","value","preferredSite","identityServiceUrl","userId"],"sources":["index.js"],"sourcesContent":["import assert from 'assert';\n\nimport uuid from 'uuid';\nimport btoa from 'btoa';\nimport _ from 'lodash';\nimport randomName from 'node-random-name';\nimport {request} from '@webex/http-core';\n\nconst BASE_PATH_SECURE = '/users/test_users_s';\nconst BASE_PATH = '/users/test_users';\n\n/**\n * Computes `expires` and `refresh_token_expires` from `expires_in` and\n * `refresh_token_expires_in` and creates an `authorization` string.\n * @param {Object} token\n * @private\n * @returns {Object}\n */\nfunction fixToken(token) {\n const now = Date.now();\n\n if (token.expires_in && !token.expires) {\n token.expires = now + token.expires_in * 1000;\n }\n\n if (token.refresh_token_expires_in && !token.refresh_token_expires) {\n /* eslint camelcase: [0] */\n token.refresh_token_expires = now + token.refresh_token_expires_in * 1000;\n }\n\n if (token.token_type && token.access_token) {\n token.authorization = `${token.token_type} ${token.access_token}`;\n }\n\n return token;\n}\n\nlet clientToken;\n\n/**\n * Fetches credentials to talk to the test_users_s endpoint\n *\n * Caches result in `clientToken` variable for multiple runs\n * @param {Object} options\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.idbrokerUrl\n * @private\n * @returns {String}\n */\nfunction getClientCredentials({clientId, clientSecret, idbrokerUrl}) {\n if (clientToken) {\n return Promise.resolve(clientToken);\n }\n\n return request({\n method: 'POST',\n uri: `${idbrokerUrl}/idb/oauth2/v1/access_token`,\n json: true,\n form: {\n grant_type: 'client_credentials',\n scope: 'Identity:SCIM webexsquare:get_conversation',\n client_id: clientId,\n client_secret: clientSecret,\n },\n headers: {\n // Note: we can't request's auth hash here because this endpoint expects\n // us to send the auth header *without including \"Basic \"* before the\n // token string\n authorization: btoa(`${clientId}:${clientSecret}`),\n },\n })\n .then((res) => {\n const token = fixToken(res.body);\n\n return `${token.token_type} ${token.access_token}`;\n })\n .then((token) => {\n clientToken = token;\n\n return clientToken;\n });\n}\n\n/**\n * Makes a request authorized with client credentials\n * @param {Object} options\n * @param {Object} options.body\n * @param {string} options.body.clientId\n * @param {string} options.body.clientSecret\n * @param {string} options.body.idbrokerUrl\n * @private\n * @returns {Promise<HttpResponseObject>}\n */\nfunction requestWithAuth(options) {\n return getClientCredentials(options.body).then((authorization) => {\n options.headers = options.headers || {};\n options.headers.authorization = authorization;\n\n return request(options);\n });\n}\n\n/**\n * @typedef {Object} AccessTokenObject\n * @property {string} token.access_token\n * @property {Number} token.expires_in\n * @property {string} token.token_type\n * @property {string} token.refresh_token\n * @property {Number} token.refresh_token_expires_in\n * @property {string} token.expires\n * @property {string} token.refresh_token_expires\n */\n\n/**\n * @typedef {Object} CreateUserOptions\n * @property {boolean} [authCodeOnly] generates auth_code\n * @param {string} [clientId] defaults to WEBEX_CLIENT_ID\n * @param {string} [clientSecret] defaults to WEBEX_CLIENT_SECRET\n * @param {string} [cigServiceUrl] defaults to WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL\n * @property {string} [displayName]\n * @property {string} [emailAddress]\n * @property {Array.<string>} [entitlements]\n * @param {string} [idbrokerUrl] defaults to IDBROKER_BASE_URL\n * @property {string} [machineType] used when creating a machine user/device\n * @property {string} [orgId] organization ID to create the user under\n * @property {string} [password] defaults to a random password\n * @property {string} [roles] defaults to []\n * @property {string} [scope] defaults to WEBEX_SCOPE\n * @property {string} [type] used to create a machine\n * @property {boolean} [forceCreate] force creates the user, to be used in conjunction with ensureExistsInWebexSites\n * @property {boolean} [ensureExistsInWebexSites] syncs the user in provided webexSites (syncInWebexSites)\n * @property {Array.<string>} [syncInWebexSites] used to define in which sites account should be synced\n * @property {string} [orgAdminAuthorization] bearer token of org admin to use syncInWebexSites\n */\n\n/**\n * @typedef {Object} TestUserObject\n * @property {string} password\n * @property {string} emailAddress\n * @property {string} displayName\n * @property {string} id\n * @property {string} userName\n * @property {string} email\n * @property {string} name\n * @property {string} givenName\n * @property {string} type\n * @property {Array.<string>} entitlements\n * @property {string} orgId\n * @property {AccessTokenObject} token\n */\n\n/**\n * Creates a test user\n * @param {CreateUserOptions} options\n * @returns {Promise.<TestUserObject>}\n */\nexport function createTestUser(options = {}) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!idbrokerUrl) {\n throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n const body = {\n authCodeOnly: options.authCodeOnly,\n clientId,\n clientSecret,\n displayName: options.displayName || randomName(),\n emailTemplate: options.emailAddress,\n entitlements: options.entitlements || [\n 'spark',\n 'squaredCallInitiation',\n 'squaredRoomModeration',\n 'squaredInviter',\n 'webExSquared',\n 'basicMessage',\n ],\n idbrokerUrl,\n machineType: options.machineType,\n orgId: options.orgId,\n // The five characters on the end are to hit all the password requirements\n password: options.password || `${uuid.v4()}zAY1*`,\n roles: options.roles || [],\n scopes: options.scope || process.env.WEBEX_SCOPE,\n type: options.type,\n forceCreate: options.forceCreate || false,\n ensureExistsInWebexSites: options.ensureExistsInWebexSites || false,\n syncInWebexSites: options.syncInWebexSites,\n orgAdminAuthorization: options.orgAdminAuthorization,\n };\n\n return requestWithAuth({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH_SECURE}`,\n json: true,\n body,\n }).then((res) => ({\n password: body.password,\n emailAddress: res.body.user.email,\n displayName: res.body.user.name,\n ...res.body.user,\n token: fixToken(res.body.token),\n }));\n}\n\n/**\n * Exchanges a user name/password for an access token\n * @param {Object} options\n * @param {string} options.id\n * @param {string} options.email\n * @param {string} options.password\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.cigServiceUrl\n * @returns {Promise.<AccessTokenObject>}\n */\nexport function loginTestUser(options) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n return request({\n method: 'POST',\n uri: `${cigServiceUrl}${BASE_PATH}/login`,\n json: true,\n body: _.defaultsDeep(options, {\n clientId,\n clientSecret,\n }),\n }).then((res) => fixToken(res.body));\n}\n\n/**\n * Removes a test user\n * @param {Object} options\n * @param {string} options.id user id to remove\n * @param {string} options.cigServiceUrl\n * @param {Object} options.token\n * @param {string} options.token.authorization\n * @param {string} [options.token.refresh_token]\n * @returns {Promise}\n */\nexport function removeTestUser(options = {}) {\n const cigServiceUrl =\n options.cigServiceUrl ||\n process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL ||\n process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;\n\n if (!cigServiceUrl) {\n throw new Error(\n 'options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined'\n );\n }\n\n if (!options.id) {\n return Promise.reject(new Error('options.id is required'));\n }\n\n if (!options.token) {\n return loginTestUser(options).then((token) => {\n options.token = token;\n\n return removeTestUser(options);\n });\n }\n\n assert(options.token.authorization, 'options.token.authorization must be defined');\n\n return request({\n method: 'POST',\n json: true,\n headers: {\n authorization: options.token.authorization,\n },\n body: {\n /* eslint-disable camelcase */\n user_id: options.id,\n refresh_token: options.token.refresh_token,\n user_type: options.userType || 'PERSON',\n /* eslint-enable camelcase */\n },\n uri: `${cigServiceUrl}${BASE_PATH}/delete`,\n });\n}\n\n/**\n * Sets the preferredWebexSite for the provided user\n *\n * This method should be used to ensure a created test user has the right webex site set.\n *\n * @param {Object} options\n * @param {string} options.userId user id to set site\n * @param {string} options.preferredSite new preferred webexsite\n * @param {string} options.orgId orgId of the site\n * @param {string} options.identityServiceUrl url of identity service\n * @param {string} options.authorization\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @returns {Promise}\n */\nexport function setPreferredSite(options = {}) {\n const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;\n const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;\n\n if (!clientId) {\n throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');\n }\n\n if (!clientSecret) {\n throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');\n }\n\n /* eslint-disable no-useless-escape */\n const body = {\n schemas: ['urn:scim:schemas:core:1.0', 'urn:scim:schemas:extension:cisco:commonidentity:1.0'],\n userPreferences: [\n {\n value: `\\\"preferredWebExSite\\\":\\\"${options.preferredSite}\\\"`,\n },\n ],\n };\n /* eslint-enable no-useless-escape */\n\n return request({\n method: 'PATCH',\n headers: {\n authorization: options.authorization,\n },\n uri: `${options.identityServiceUrl}/identity/scim/${options.orgId}/v1/Users/${options.userId}`,\n json: true,\n body,\n });\n}\n\nexport {\n default as createWhistlerTestUser,\n removeTestUser as removeWhistlerTestUser,\n} from './whistler';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA;AACA;AAEA;AACA;AA8WA;AAGoB;AAAA;AAAA;AAAA;AA/WpB,IAAMA,gBAAgB,GAAG,qBAAqB;AAC9C,IAAMC,SAAS,GAAG,mBAAmB;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQ,CAACC,KAAK,EAAE;EACvB,IAAMC,GAAG,GAAG,mBAAU;EAEtB,IAAID,KAAK,CAACE,UAAU,IAAI,CAACF,KAAK,CAACG,OAAO,EAAE;IACtCH,KAAK,CAACG,OAAO,GAAGF,GAAG,GAAGD,KAAK,CAACE,UAAU,GAAG,IAAI;EAC/C;EAEA,IAAIF,KAAK,CAACI,wBAAwB,IAAI,CAACJ,KAAK,CAACK,qBAAqB,EAAE;IAClE;IACAL,KAAK,CAACK,qBAAqB,GAAGJ,GAAG,GAAGD,K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J;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS0E,gBAAgB,GAAe;EAAA,IAAd1C,OAAO,uEAAG,CAAC,CAAC;EAC3C,IAAMnB,QAAQ,GAAGmB,OAAO,CAACnB,QAAQ,IAAIqB,OAAO,CAACC,GAAG,CAACC,eAAe;EAChE,IAAMtB,YAAY,GAAGkB,OAAO,CAAClB,YAAY,IAAIoB,OAAO,CAACC,GAAG,CAACE,mBAAmB;EAE5E,IAAI,CAACxB,QAAQ,EAAE;IACb,MAAM,IAAI6B,KAAK,CAAC,iEAAiE,CAAC;EACpF;EAEA,IAAI,CAAC5B,YAAY,EAAE;IACjB,MAAM,IAAI4B,KAAK,CAAC,yEAAyE,CAAC;EAC5F;;EAEA;EACA,IAAMZ,IAAI,GAAG;IACX6C,OAAO,EAAE,CAAC,2BAA2B,EAAE,qDAAqD,CAAC;IAC7FC,eAAe,EAAE,CACf;MACEC,KAAK,qCAA8B7C,OAAO,CAAC8C,aAAa;IAC1D,CAAC;EAEL,CAAC;EACD;;EAEA,OAAO,IAAA7D,iBAAO,EAAC;IACbC,MAAM,EAAE,OAAO;IACfQ,OAAO,EAAE;MACPhB,aAAa,EAAEsB,OAAO,CAACtB;IACzB,CAAC;IACDS,GAAG,YAAKa,OAAO,CAAC+C,kBAAkB,4BAAkB/C,OAAO,CAACkB,KAAK,uBAAalB,OAAO,CAACgD,MAAM,CAAE;IAC9F5D,IAAI,EAAE,IAAI;IACVU,IAAI,EAAJA;EACF,CAAC,CAAC;AACJ"}
|
package/dist/whistler.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
4
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
5
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
6
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
7
|
+
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
3
8
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
9
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
10
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
11
|
value: true
|
|
9
12
|
});
|
|
10
|
-
|
|
11
13
|
exports.default = createTestUser;
|
|
12
14
|
exports.removeTestUser = removeTestUser;
|
|
13
|
-
|
|
14
|
-
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
15
|
-
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
16
16
|
var _btoa = _interopRequireDefault(require("btoa"));
|
|
17
|
-
|
|
18
17
|
var _httpCore = require("@webex/http-core");
|
|
19
|
-
|
|
18
|
+
var _nodeRandomName = _interopRequireDefault(require("node-random-name"));
|
|
19
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
20
22
|
/**
|
|
21
23
|
* Fetches credentials/access_token to talk to the whistler endpoint
|
|
22
24
|
*
|
|
@@ -32,11 +34,11 @@ var _httpCore = require("@webex/http-core");
|
|
|
32
34
|
*/
|
|
33
35
|
var getClientCredentials = function getClientCredentials(_ref) {
|
|
34
36
|
var clientId = _ref.clientId,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
clientSecret = _ref.clientSecret,
|
|
38
|
+
orgId = _ref.orgId,
|
|
39
|
+
idbrokerUrl = _ref.idbrokerUrl,
|
|
40
|
+
machineAccount = _ref.machineAccount,
|
|
41
|
+
machinePassword = _ref.machinePassword;
|
|
40
42
|
return (0, _httpCore.request)({
|
|
41
43
|
method: 'POST',
|
|
42
44
|
uri: "".concat(idbrokerUrl, "/idb/token/").concat(orgId, "/v2/actions/GetBearerToken/invoke"),
|
|
@@ -70,15 +72,16 @@ var getClientCredentials = function getClientCredentials(_ref) {
|
|
|
70
72
|
return "".concat(res.body.token_type, " ").concat(res.body.access_token);
|
|
71
73
|
});
|
|
72
74
|
};
|
|
75
|
+
|
|
73
76
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
* @typedef {Object} TestUserObject
|
|
78
|
+
* @property {string} password
|
|
79
|
+
* @property {string} emailAddress
|
|
80
|
+
* @property {string} displayName
|
|
81
|
+
* @property {string} token
|
|
82
|
+
* @property {string} reservationUrl
|
|
83
|
+
* @property {object} responseMetaData - whistler given properties
|
|
84
|
+
*/
|
|
82
85
|
|
|
83
86
|
/**
|
|
84
87
|
* @typedef {Object} CreateUserOptions
|
|
@@ -97,50 +100,41 @@ var getClientCredentials = function getClientCredentials(_ref) {
|
|
|
97
100
|
* @param {CreateUserOptions} options
|
|
98
101
|
* @returns {Promise.<TestUserObject>}
|
|
99
102
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
103
|
function createTestUser() {
|
|
103
104
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
104
105
|
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
105
106
|
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
106
|
-
var machineAccount = options.machineAccount || process.env.WHISTLER_MACHINE_ACCOUNT;
|
|
107
|
-
var machinePassword = options.machinePassword || process.env.WHISTLER_MACHINE_PASSWORD;
|
|
107
|
+
var machineAccount = options.machineAccount || process.env.WHISTLER_MACHINE_ACCOUNT || (0, _nodeRandomName.default)();
|
|
108
|
+
var machinePassword = options.machinePassword || process.env.WHISTLER_MACHINE_PASSWORD || "".concat(_uuid.default.v4(), "zAY1*");
|
|
108
109
|
var idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;
|
|
109
110
|
var orgId = options.orgId || process.env.WHISTLER_TEST_ORG_ID;
|
|
110
111
|
var whistlerServiceUrl = options.whistlerServiceUrl || process.env.WHISTLER_API_SERVICE_URL;
|
|
111
112
|
var reservationGroup = options.reservationGroup,
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
userScopes = options.userScopes;
|
|
114
114
|
if (!clientId) {
|
|
115
115
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
116
116
|
}
|
|
117
|
-
|
|
118
117
|
if (!clientSecret) {
|
|
119
118
|
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
120
119
|
}
|
|
121
|
-
|
|
122
120
|
if (!machineAccount) {
|
|
123
121
|
throw new Error('options.machineAccount or process.env.WHISTLER_MACHINE_ACCOUNT must be defined');
|
|
124
122
|
}
|
|
125
|
-
|
|
126
123
|
if (!machinePassword) {
|
|
127
124
|
throw new Error('options.machinePassword or process.env.WHISTLER_MACHINE_PASSWORD must be defined');
|
|
128
125
|
}
|
|
129
|
-
|
|
130
126
|
if (!idbrokerUrl) {
|
|
131
127
|
throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');
|
|
132
128
|
}
|
|
133
|
-
|
|
134
129
|
if (!orgId) {
|
|
135
130
|
throw new Error('options.orgId or process.env.WHISTLER_TEST_ORG_ID must be defined');
|
|
136
131
|
}
|
|
137
|
-
|
|
138
132
|
if (!whistlerServiceUrl) {
|
|
139
133
|
throw new Error('options.whistlerServiceUrl or process.env.WHISTLER_API_SERVICE_URL must be defined');
|
|
140
|
-
}
|
|
141
|
-
// Please check https://confluence-eng-gpk2.cisco.com/conf/pages/viewpage.action?spaceKey=LOCUS&title=Whistler+APIs#WhistlerAPIs-GET/reservations/testUser
|
|
142
|
-
|
|
134
|
+
}
|
|
143
135
|
|
|
136
|
+
// For reservation groups and user scopes
|
|
137
|
+
// Please check https://confluence-eng-gpk2.cisco.com/conf/pages/viewpage.action?spaceKey=LOCUS&title=Whistler+APIs#WhistlerAPIs-GET/reservations/testUser
|
|
144
138
|
return getClientCredentials({
|
|
145
139
|
clientId: clientId,
|
|
146
140
|
clientSecret: clientSecret,
|
|
@@ -162,7 +156,7 @@ function createTestUser() {
|
|
|
162
156
|
}
|
|
163
157
|
});
|
|
164
158
|
}).then(function (res) {
|
|
165
|
-
return (
|
|
159
|
+
return _objectSpread({
|
|
166
160
|
password: res.body.responseMetaData.ciPassword,
|
|
167
161
|
emailAddress: res.body.responseMetaData.name,
|
|
168
162
|
displayName: res.body.responseMetaData.webExUserName,
|
|
@@ -171,13 +165,12 @@ function createTestUser() {
|
|
|
171
165
|
}, res.body.responseMetaData);
|
|
172
166
|
});
|
|
173
167
|
}
|
|
168
|
+
|
|
174
169
|
/**
|
|
175
170
|
*
|
|
176
171
|
* @param {Object} options
|
|
177
172
|
* @returns {Promise}
|
|
178
173
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
174
|
function removeTestUser() {
|
|
182
175
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
183
176
|
return (0, _httpCore.request)({
|