@webex/test-users 3.0.0-beta.2 → 3.0.0-beta.21
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 +34 -74
- package/dist/index.js.map +1 -1
- package/dist/whistler.js +28 -37
- package/dist/whistler.js.map +1 -1
- package/package.json +4 -4
- package/src/index.js +65 -52
- package/src/whistler.js +69 -57
- 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,49 @@
|
|
|
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
|
-
|
|
36
30
|
var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
|
|
37
|
-
|
|
38
31
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
39
|
-
|
|
40
|
-
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
41
|
-
|
|
32
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
42
33
|
var _defaultsDeep2 = _interopRequireDefault(require("lodash/defaultsDeep"));
|
|
43
|
-
|
|
44
34
|
var _assert = _interopRequireDefault(require("assert"));
|
|
45
|
-
|
|
46
35
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
47
|
-
|
|
48
36
|
var _btoa = _interopRequireDefault(require("btoa"));
|
|
49
|
-
|
|
50
37
|
var _nodeRandomName = _interopRequireDefault(require("node-random-name"));
|
|
51
|
-
|
|
52
38
|
var _httpCore = require("@webex/http-core");
|
|
53
|
-
|
|
54
39
|
var _whistler = _interopRequireWildcard(require("./whistler"));
|
|
55
|
-
|
|
56
40
|
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
41
|
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
|
-
|
|
42
|
+
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; }
|
|
43
|
+
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
44
|
var BASE_PATH_SECURE = '/users/test_users_s';
|
|
61
45
|
var BASE_PATH = '/users/test_users';
|
|
46
|
+
|
|
62
47
|
/**
|
|
63
48
|
* Computes `expires` and `refresh_token_expires` from `expires_in` and
|
|
64
49
|
* `refresh_token_expires_in` and creates an `authorization` string.
|
|
@@ -66,27 +51,22 @@ var BASE_PATH = '/users/test_users';
|
|
|
66
51
|
* @private
|
|
67
52
|
* @returns {Object}
|
|
68
53
|
*/
|
|
69
|
-
|
|
70
54
|
function fixToken(token) {
|
|
71
55
|
var now = (0, _now.default)();
|
|
72
|
-
|
|
73
56
|
if (token.expires_in && !token.expires) {
|
|
74
57
|
token.expires = now + token.expires_in * 1000;
|
|
75
58
|
}
|
|
76
|
-
|
|
77
59
|
if (token.refresh_token_expires_in && !token.refresh_token_expires) {
|
|
78
60
|
/* eslint camelcase: [0] */
|
|
79
61
|
token.refresh_token_expires = now + token.refresh_token_expires_in * 1000;
|
|
80
62
|
}
|
|
81
|
-
|
|
82
63
|
if (token.token_type && token.access_token) {
|
|
83
64
|
token.authorization = "".concat(token.token_type, " ").concat(token.access_token);
|
|
84
65
|
}
|
|
85
|
-
|
|
86
66
|
return token;
|
|
87
67
|
}
|
|
88
|
-
|
|
89
68
|
var clientToken;
|
|
69
|
+
|
|
90
70
|
/**
|
|
91
71
|
* Fetches credentials to talk to the test_users_s endpoint
|
|
92
72
|
*
|
|
@@ -98,16 +78,13 @@ var clientToken;
|
|
|
98
78
|
* @private
|
|
99
79
|
* @returns {String}
|
|
100
80
|
*/
|
|
101
|
-
|
|
102
81
|
function getClientCredentials(_ref) {
|
|
103
82
|
var clientId = _ref.clientId,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
83
|
+
clientSecret = _ref.clientSecret,
|
|
84
|
+
idbrokerUrl = _ref.idbrokerUrl;
|
|
107
85
|
if (clientToken) {
|
|
108
86
|
return _promise.default.resolve(clientToken);
|
|
109
87
|
}
|
|
110
|
-
|
|
111
88
|
return (0, _httpCore.request)({
|
|
112
89
|
method: 'POST',
|
|
113
90
|
uri: "".concat(idbrokerUrl, "/idb/oauth2/v1/access_token"),
|
|
@@ -132,6 +109,7 @@ function getClientCredentials(_ref) {
|
|
|
132
109
|
return clientToken;
|
|
133
110
|
});
|
|
134
111
|
}
|
|
112
|
+
|
|
135
113
|
/**
|
|
136
114
|
* Makes a request authorized with client credentials
|
|
137
115
|
* @param {Object} options
|
|
@@ -142,8 +120,6 @@ function getClientCredentials(_ref) {
|
|
|
142
120
|
* @private
|
|
143
121
|
* @returns {Promise<HttpResponseObject>}
|
|
144
122
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
123
|
function requestWithAuth(options) {
|
|
148
124
|
return getClientCredentials(options.body).then(function (authorization) {
|
|
149
125
|
options.headers = options.headers || {};
|
|
@@ -151,6 +127,7 @@ function requestWithAuth(options) {
|
|
|
151
127
|
return (0, _httpCore.request)(options);
|
|
152
128
|
});
|
|
153
129
|
}
|
|
130
|
+
|
|
154
131
|
/**
|
|
155
132
|
* @typedef {Object} AccessTokenObject
|
|
156
133
|
* @property {string} token.access_token
|
|
@@ -181,51 +158,44 @@ function requestWithAuth(options) {
|
|
|
181
158
|
*/
|
|
182
159
|
|
|
183
160
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
161
|
+
* @typedef {Object} TestUserObject
|
|
162
|
+
* @property {string} password
|
|
163
|
+
* @property {string} emailAddress
|
|
164
|
+
* @property {string} displayName
|
|
165
|
+
* @property {string} id
|
|
166
|
+
* @property {string} userName
|
|
167
|
+
* @property {string} email
|
|
168
|
+
* @property {string} name
|
|
169
|
+
* @property {string} givenName
|
|
170
|
+
* @property {string} type
|
|
171
|
+
* @property {Array.<string>} entitlements
|
|
172
|
+
* @property {string} orgId
|
|
173
|
+
* @property {AccessTokenObject} token
|
|
174
|
+
*/
|
|
198
175
|
|
|
199
176
|
/**
|
|
200
177
|
* Creates a test user
|
|
201
178
|
* @param {CreateUserOptions} options
|
|
202
179
|
* @returns {Promise.<TestUserObject>}
|
|
203
180
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
181
|
function createTestUser() {
|
|
207
182
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
208
183
|
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
209
184
|
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
210
185
|
var idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;
|
|
211
186
|
var cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
212
|
-
|
|
213
187
|
if (!clientId) {
|
|
214
188
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
215
189
|
}
|
|
216
|
-
|
|
217
190
|
if (!clientSecret) {
|
|
218
191
|
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
219
192
|
}
|
|
220
|
-
|
|
221
193
|
if (!idbrokerUrl) {
|
|
222
194
|
throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');
|
|
223
195
|
}
|
|
224
|
-
|
|
225
196
|
if (!cigServiceUrl) {
|
|
226
197
|
throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');
|
|
227
198
|
}
|
|
228
|
-
|
|
229
199
|
var body = {
|
|
230
200
|
authCodeOnly: options.authCodeOnly,
|
|
231
201
|
clientId: clientId,
|
|
@@ -248,15 +218,16 @@ function createTestUser() {
|
|
|
248
218
|
json: true,
|
|
249
219
|
body: body
|
|
250
220
|
}).then(function (res) {
|
|
251
|
-
return (
|
|
221
|
+
return _objectSpread(_objectSpread({
|
|
252
222
|
password: body.password,
|
|
253
223
|
emailAddress: res.body.user.email,
|
|
254
224
|
displayName: res.body.user.name
|
|
255
|
-
}, res.body.user, {
|
|
225
|
+
}, res.body.user), {}, {
|
|
256
226
|
token: fixToken(res.body.token)
|
|
257
227
|
});
|
|
258
228
|
});
|
|
259
229
|
}
|
|
230
|
+
|
|
260
231
|
/**
|
|
261
232
|
* Exchanges a user name/password for an access token
|
|
262
233
|
* @param {Object} options
|
|
@@ -268,25 +239,19 @@ function createTestUser() {
|
|
|
268
239
|
* @param {string} options.cigServiceUrl
|
|
269
240
|
* @returns {Promise.<AccessTokenObject>}
|
|
270
241
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
242
|
function loginTestUser(options) {
|
|
274
243
|
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
275
244
|
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
276
245
|
var cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
277
|
-
|
|
278
246
|
if (!clientId) {
|
|
279
247
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
280
248
|
}
|
|
281
|
-
|
|
282
249
|
if (!clientSecret) {
|
|
283
250
|
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
284
251
|
}
|
|
285
|
-
|
|
286
252
|
if (!cigServiceUrl) {
|
|
287
253
|
throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');
|
|
288
254
|
}
|
|
289
|
-
|
|
290
255
|
return (0, _httpCore.request)({
|
|
291
256
|
method: 'POST',
|
|
292
257
|
uri: "".concat(cigServiceUrl).concat(BASE_PATH, "/login"),
|
|
@@ -299,6 +264,7 @@ function loginTestUser(options) {
|
|
|
299
264
|
return fixToken(res.body);
|
|
300
265
|
});
|
|
301
266
|
}
|
|
267
|
+
|
|
302
268
|
/**
|
|
303
269
|
* Removes a test user
|
|
304
270
|
* @param {Object} options
|
|
@@ -309,27 +275,21 @@ function loginTestUser(options) {
|
|
|
309
275
|
* @param {string} [options.token.refresh_token]
|
|
310
276
|
* @returns {Promise}
|
|
311
277
|
*/
|
|
312
|
-
|
|
313
|
-
|
|
314
278
|
function removeTestUser() {
|
|
315
279
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
316
280
|
var cigServiceUrl = options.cigServiceUrl || process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL || process.env.WEBEX_TEST_USERS_CONVERSATION_SERVICE_URL;
|
|
317
|
-
|
|
318
281
|
if (!cigServiceUrl) {
|
|
319
282
|
throw new Error('options.cigServiceUrl or process.env.WEBEX_TEST_USERS_CI_GATEWAY_SERVICE_URL must be defined');
|
|
320
283
|
}
|
|
321
|
-
|
|
322
284
|
if (!options.id) {
|
|
323
285
|
return _promise.default.reject(new Error('options.id is required'));
|
|
324
286
|
}
|
|
325
|
-
|
|
326
287
|
if (!options.token) {
|
|
327
288
|
return loginTestUser(options).then(function (token) {
|
|
328
289
|
options.token = token;
|
|
329
290
|
return removeTestUser(options);
|
|
330
291
|
});
|
|
331
292
|
}
|
|
332
|
-
|
|
333
293
|
(0, _assert.default)(options.token.authorization, 'options.token.authorization must be defined');
|
|
334
294
|
return (0, _httpCore.request)({
|
|
335
295
|
method: 'POST',
|
|
@@ -343,8 +303,8 @@ function removeTestUser() {
|
|
|
343
303
|
refresh_token: options.token.refresh_token,
|
|
344
304
|
user_type: options.userType || 'PERSON'
|
|
345
305
|
/* eslint-enable camelcase */
|
|
346
|
-
|
|
347
306
|
},
|
|
307
|
+
|
|
348
308
|
uri: "".concat(cigServiceUrl).concat(BASE_PATH, "/delete")
|
|
349
309
|
});
|
|
350
310
|
}
|
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,UAAN,IAAoB,CAACF,KAAK,CAACG,OAA/B,EAAwC;IACtCH,KAAK,CAACG,OA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AoB;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","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).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 =\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 ],\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 }).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\nexport {\n default as createWhistlerTestUser,\n removeTestUser as removeWhistlerTestUser,\n} from './whistler';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAEA;AACA;AAEA;AACA;AAoTA;AAGoB;AAAA;AAAA;AAAA;AArTpB,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,KAAK,CAACI,wBAAwB,GAAG,IAAI;EAC3E;EAEA,IAAIJ,KAA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AACM,yCAAyC;EAEvD,IAAI,CAACF,aAAa,EAAE;IAClB,MAAM,IAAIG,KAAK,CACb,8FAA8F,CAC/F;EACH;EAEA,IAAI,CAACV,OAAO,CAAC+B,EAAE,EAAE;IACf,OAAO,iBAAQC,MAAM,CAAC,IAAItB,KAAK,CAAC,wBAAwB,CAAC,CAAC;EAC5D;EAEA,IAAI,CAACV,OAAO,CAAC9B,KAAK,EAAE;IAClB,OAAO2D,aAAa,CAAC7B,OAAO,CAAC,CAACJ,IAAI,CAAC,UAAC1B,KAAK,EAAK;MAC5C8B,OAAO,CAAC9B,KAAK,GAAGA,KAAK;MAErB,OAAO4D,cAAc,CAAC9B,OAAO,CAAC;IAChC,CAAC,CAAC;EACJ;EAEA,IAAAiC,eAAM,EAACjC,OAAO,CAAC9B,KAAK,CAACQ,aAAa,EAAE,6CAA6C,CAAC;EAElF,OAAO,IAAAO,iBAAO,EAAC;IACbC,MAAM,EAAE,MAAM;IACdE,IAAI,EAAE,IAAI;IACVM,OAAO,EAAE;MACPhB,aAAa,EAAEsB,OAAO,CAAC9B,KAAK,CAACQ;IAC/B,CAAC;IACDoB,IAAI,EAAE;MACJ;MACAoC,OAAO,EAAElC,OAAO,CAAC+B,EAAE;MACnBI,aAAa,EAAEnC,OAAO,CAAC9B,KAAK,CAACiE,aAAa;MAC1CC,SAAS,EAAEpC,OAAO,CAACqC,QAAQ,IAAI;MAC/B;IACF,CAAC;;IACDlD,GAAG,YAAKoB,aAAa,SAAGvC,SAAS;EACnC,CAAC,CAAC;AACJ"}
|
package/dist/whistler.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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
|
+
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; }
|
|
19
|
+
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
20
|
/**
|
|
21
21
|
* Fetches credentials/access_token to talk to the whistler endpoint
|
|
22
22
|
*
|
|
@@ -32,11 +32,11 @@ var _httpCore = require("@webex/http-core");
|
|
|
32
32
|
*/
|
|
33
33
|
var getClientCredentials = function getClientCredentials(_ref) {
|
|
34
34
|
var clientId = _ref.clientId,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
clientSecret = _ref.clientSecret,
|
|
36
|
+
orgId = _ref.orgId,
|
|
37
|
+
idbrokerUrl = _ref.idbrokerUrl,
|
|
38
|
+
machineAccount = _ref.machineAccount,
|
|
39
|
+
machinePassword = _ref.machinePassword;
|
|
40
40
|
return (0, _httpCore.request)({
|
|
41
41
|
method: 'POST',
|
|
42
42
|
uri: "".concat(idbrokerUrl, "/idb/token/").concat(orgId, "/v2/actions/GetBearerToken/invoke"),
|
|
@@ -70,15 +70,16 @@ var getClientCredentials = function getClientCredentials(_ref) {
|
|
|
70
70
|
return "".concat(res.body.token_type, " ").concat(res.body.access_token);
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
+
|
|
73
74
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
* @typedef {Object} TestUserObject
|
|
76
|
+
* @property {string} password
|
|
77
|
+
* @property {string} emailAddress
|
|
78
|
+
* @property {string} displayName
|
|
79
|
+
* @property {string} token
|
|
80
|
+
* @property {string} reservationUrl
|
|
81
|
+
* @property {object} responseMetaData - whistler given properties
|
|
82
|
+
*/
|
|
82
83
|
|
|
83
84
|
/**
|
|
84
85
|
* @typedef {Object} CreateUserOptions
|
|
@@ -97,8 +98,6 @@ var getClientCredentials = function getClientCredentials(_ref) {
|
|
|
97
98
|
* @param {CreateUserOptions} options
|
|
98
99
|
* @returns {Promise.<TestUserObject>}
|
|
99
100
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
101
|
function createTestUser() {
|
|
103
102
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
104
103
|
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
@@ -109,38 +108,31 @@ function createTestUser() {
|
|
|
109
108
|
var orgId = options.orgId || process.env.WHISTLER_TEST_ORG_ID;
|
|
110
109
|
var whistlerServiceUrl = options.whistlerServiceUrl || process.env.WHISTLER_API_SERVICE_URL;
|
|
111
110
|
var reservationGroup = options.reservationGroup,
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
userScopes = options.userScopes;
|
|
114
112
|
if (!clientId) {
|
|
115
113
|
throw new Error('options.clientId or process.env.WEBEX_CLIENT_ID must be defined');
|
|
116
114
|
}
|
|
117
|
-
|
|
118
115
|
if (!clientSecret) {
|
|
119
116
|
throw new Error('options.clientSecret or process.env.WEBEX_CLIENT_SECRET must be defined');
|
|
120
117
|
}
|
|
121
|
-
|
|
122
118
|
if (!machineAccount) {
|
|
123
119
|
throw new Error('options.machineAccount or process.env.WHISTLER_MACHINE_ACCOUNT must be defined');
|
|
124
120
|
}
|
|
125
|
-
|
|
126
121
|
if (!machinePassword) {
|
|
127
122
|
throw new Error('options.machinePassword or process.env.WHISTLER_MACHINE_PASSWORD must be defined');
|
|
128
123
|
}
|
|
129
|
-
|
|
130
124
|
if (!idbrokerUrl) {
|
|
131
125
|
throw new Error('options.idbrokerUrl or process.env.IDBROKER_BASE_URL must be defined');
|
|
132
126
|
}
|
|
133
|
-
|
|
134
127
|
if (!orgId) {
|
|
135
128
|
throw new Error('options.orgId or process.env.WHISTLER_TEST_ORG_ID must be defined');
|
|
136
129
|
}
|
|
137
|
-
|
|
138
130
|
if (!whistlerServiceUrl) {
|
|
139
131
|
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
|
-
|
|
132
|
+
}
|
|
143
133
|
|
|
134
|
+
// For reservation groups and user scopes
|
|
135
|
+
// Please check https://confluence-eng-gpk2.cisco.com/conf/pages/viewpage.action?spaceKey=LOCUS&title=Whistler+APIs#WhistlerAPIs-GET/reservations/testUser
|
|
144
136
|
return getClientCredentials({
|
|
145
137
|
clientId: clientId,
|
|
146
138
|
clientSecret: clientSecret,
|
|
@@ -162,7 +154,7 @@ function createTestUser() {
|
|
|
162
154
|
}
|
|
163
155
|
});
|
|
164
156
|
}).then(function (res) {
|
|
165
|
-
return (
|
|
157
|
+
return _objectSpread({
|
|
166
158
|
password: res.body.responseMetaData.ciPassword,
|
|
167
159
|
emailAddress: res.body.responseMetaData.name,
|
|
168
160
|
displayName: res.body.responseMetaData.webExUserName,
|
|
@@ -171,13 +163,12 @@ function createTestUser() {
|
|
|
171
163
|
}, res.body.responseMetaData);
|
|
172
164
|
});
|
|
173
165
|
}
|
|
166
|
+
|
|
174
167
|
/**
|
|
175
168
|
*
|
|
176
169
|
* @param {Object} options
|
|
177
170
|
* @returns {Promise}
|
|
178
171
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
172
|
function removeTestUser() {
|
|
182
173
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
183
174
|
return (0, _httpCore.request)({
|
package/dist/whistler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getClientCredentials","clientId","clientSecret","orgId","idbrokerUrl","machineAccount","machinePassword","request","method","uri","json","body","uid","password","then","res","form","assertion","BearerToken","grant_type","scope","self_contained_token","client_id","client_secret","headers","authorization","btoa","token_type","access_token","createTestUser","options","process","env","WEBEX_CLIENT_ID","WEBEX_CLIENT_SECRET","WHISTLER_MACHINE_ACCOUNT","WHISTLER_MACHINE_PASSWORD","IDBROKER_BASE_URL","WHISTLER_TEST_ORG_ID","whistlerServiceUrl","WHISTLER_API_SERVICE_URL","reservationGroup","userScopes","Error","qs","isAccessTokenRequired","responseMetaData","ciPassword","emailAddress","name","displayName","webExUserName","token","ciAccessToken","reservationUrl","removeTestUser"],"sources":["whistler.js"],"sourcesContent":["import btoa from 'btoa';\nimport {request} from '@webex/http-core';\n\n/**\n * Fetches credentials/access_token to talk to the whistler endpoint\n *\n * @param {Object} options\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.idbrokerUrl\n * @param {string} options.orgId\n * @param {string} options.machineAccount\n * @param {string} options.machinePassword\n * @private\n * @returns {Promise<string>}\n */\nconst getClientCredentials = ({\n clientId,\n clientSecret,\n orgId,\n idbrokerUrl,\n machineAccount,\n machinePassword
|
|
1
|
+
{"version":3,"names":["getClientCredentials","clientId","clientSecret","orgId","idbrokerUrl","machineAccount","machinePassword","request","method","uri","json","body","uid","password","then","res","form","assertion","BearerToken","grant_type","scope","self_contained_token","client_id","client_secret","headers","authorization","btoa","token_type","access_token","createTestUser","options","process","env","WEBEX_CLIENT_ID","WEBEX_CLIENT_SECRET","WHISTLER_MACHINE_ACCOUNT","WHISTLER_MACHINE_PASSWORD","IDBROKER_BASE_URL","WHISTLER_TEST_ORG_ID","whistlerServiceUrl","WHISTLER_API_SERVICE_URL","reservationGroup","userScopes","Error","qs","isAccessTokenRequired","responseMetaData","ciPassword","emailAddress","name","displayName","webExUserName","token","ciAccessToken","reservationUrl","removeTestUser"],"sources":["whistler.js"],"sourcesContent":["import btoa from 'btoa';\nimport {request} from '@webex/http-core';\n\n/**\n * Fetches credentials/access_token to talk to the whistler endpoint\n *\n * @param {Object} options\n * @param {string} options.clientId\n * @param {string} options.clientSecret\n * @param {string} options.idbrokerUrl\n * @param {string} options.orgId\n * @param {string} options.machineAccount\n * @param {string} options.machinePassword\n * @private\n * @returns {Promise<string>}\n */\nconst getClientCredentials = ({\n clientId,\n clientSecret,\n orgId,\n idbrokerUrl,\n machineAccount,\n machinePassword,\n}) =>\n request({\n method: 'POST',\n uri: `${idbrokerUrl}/idb/token/${orgId}/v2/actions/GetBearerToken/invoke`,\n json: true,\n body: {\n uid: machineAccount,\n password: machinePassword,\n },\n })\n .then((res) =>\n request({\n method: 'POST',\n uri: `${idbrokerUrl}/idb/oauth2/v1/access_token`,\n json: true,\n form: {\n assertion: res.body.BearerToken,\n grant_type: 'urn:ietf:params:oauth:grant-type:saml2-bearer',\n scope: 'webexsquare:get_conversation webexsquare:admin',\n self_contained_token: true,\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: `Basic + ${btoa(`${clientId}:${clientSecret}`)}`\n authorization: btoa(`${clientId}:${clientSecret}`),\n },\n })\n )\n .then((res) => `${res.body.token_type} ${res.body.access_token}`);\n\n/**\n * @typedef {Object} TestUserObject\n * @property {string} password\n * @property {string} emailAddress\n * @property {string} displayName\n * @property {string} token\n * @property {string} reservationUrl\n * @property {object} responseMetaData - whistler given properties\n */\n\n/**\n * @typedef {Object} CreateUserOptions\n * @param {Object} [options]\n * @param {string} [whistlerServiceUrl] defaults to WHISTLER_API_SERVICE_URL\n * @param {string} [options.clientId] defaults to WEBEX_CLIENT_ID\n * @param {string} [options.clientSecret] defaults to WEBEX_CLIENT_SECRET\n * @param {string} [options.idbrokerUrl] defaults to IDBROKER_BASE_URL\n * @param {string} [options.orgId] organization ID to create the user under\n * @param {string} [options.machineAccount] defaults to WHISTLER_MACHINE_ACCOUNT\n * @param {string} [options.machinePassword] defaults to WHISTLER_MACHINE_PASSWORD\n */\n\n/**\n * Creates a test user\n * @param {CreateUserOptions} options\n * @returns {Promise.<TestUserObject>}\n */\nexport default 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 machineAccount = options.machineAccount || process.env.WHISTLER_MACHINE_ACCOUNT;\n const machinePassword = options.machinePassword || process.env.WHISTLER_MACHINE_PASSWORD;\n const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;\n const orgId = options.orgId || process.env.WHISTLER_TEST_ORG_ID;\n const whistlerServiceUrl = options.whistlerServiceUrl || process.env.WHISTLER_API_SERVICE_URL;\n const {reservationGroup, userScopes} = options;\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 (!machineAccount) {\n throw new Error(\n 'options.machineAccount or process.env.WHISTLER_MACHINE_ACCOUNT must be defined'\n );\n }\n\n if (!machinePassword) {\n throw new Error(\n 'options.machinePassword or process.env.WHISTLER_MACHINE_PASSWORD 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 (!orgId) {\n throw new Error('options.orgId or process.env.WHISTLER_TEST_ORG_ID must be defined');\n }\n\n if (!whistlerServiceUrl) {\n throw new Error(\n 'options.whistlerServiceUrl or process.env.WHISTLER_API_SERVICE_URL must be defined'\n );\n }\n\n // For reservation groups and user scopes\n // Please check https://confluence-eng-gpk2.cisco.com/conf/pages/viewpage.action?spaceKey=LOCUS&title=Whistler+APIs#WhistlerAPIs-GET/reservations/testUser\n return getClientCredentials({\n clientId,\n clientSecret,\n machineAccount,\n machinePassword,\n idbrokerUrl,\n orgId,\n })\n .then((authorization) =>\n request({\n method: 'GET',\n uri: `${whistlerServiceUrl}/reservations/testUser`,\n qs: {\n reservationGroup,\n userScopes,\n isAccessTokenRequired: true,\n },\n headers: {\n authorization,\n },\n })\n )\n .then((res) => ({\n password: res.body.responseMetaData.ciPassword,\n emailAddress: res.body.responseMetaData.name,\n displayName: res.body.responseMetaData.webExUserName,\n token: res.body.responseMetaData.ciAccessToken,\n reservationUrl: res.body.reservationUrl,\n ...res.body.responseMetaData,\n }));\n}\n\n/**\n *\n * @param {Object} options\n * @returns {Promise}\n */\nexport function removeTestUser(options = {}) {\n return request({\n method: 'DELETE',\n headers: {\n authorization: `Bearer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c,GAAe;EAAA,IAAdzB,OAAO,uEAAG,CAAC,CAAC;EACzC,OAAO,IAAAvB,iBAAO,EAAC;IACbC,MAAM,EAAE,QAAQ;IAChBgB,OAAO,EAAE;MACPC,aAAa,mBAAYK,OAAO,CAACsB,KAAK;IACxC,CAAC;IACD3C,GAAG,EAAEqB,OAAO,CAACwB;EACf,CAAC,CAAC;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/test-users",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.21",
|
|
4
4
|
"description": "Cisco Webex Test Users",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"chai-as-promised": "^7.1.1"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@webex/http-core": "3.0.0-beta.
|
|
28
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
29
|
-
"@webex/test-users": "3.0.0-beta.
|
|
27
|
+
"@webex/http-core": "3.0.0-beta.21",
|
|
28
|
+
"@webex/test-helper-mocha": "3.0.0-beta.21",
|
|
29
|
+
"@webex/test-users": "3.0.0-beta.21",
|
|
30
30
|
"btoa": "^1.2.1",
|
|
31
31
|
"lodash": "^4.17.21",
|
|
32
32
|
"node-random-name": "^1.0.1",
|