@webex/test-users 3.0.0-beta.26 → 3.0.0-beta.261
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/whistler.js +4 -2
- package/dist/whistler.js.map +1 -1
- package/package.json +4 -4
- package/src/index.js +1 -0
- package/src/whistler.js +6 -2
package/dist/index.js
CHANGED
|
@@ -202,7 +202,7 @@ function createTestUser() {
|
|
|
202
202
|
clientSecret: clientSecret,
|
|
203
203
|
displayName: options.displayName || (0, _nodeRandomName.default)(),
|
|
204
204
|
emailTemplate: options.emailAddress,
|
|
205
|
-
entitlements: options.entitlements || ['spark', 'squaredCallInitiation', 'squaredRoomModeration', 'squaredInviter', 'webExSquared'],
|
|
205
|
+
entitlements: options.entitlements || ['spark', 'squaredCallInitiation', 'squaredRoomModeration', 'squaredInviter', 'webExSquared', 'basicMessage'],
|
|
206
206
|
idbrokerUrl: idbrokerUrl,
|
|
207
207
|
machineType: options.machineType,
|
|
208
208
|
orgId: options.orgId,
|
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).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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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"}
|
|
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 '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 };\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;AAqTA;AAGoB;AAAA;AAAA;AAAA;AAtTpB,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;I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
package/dist/whistler.js
CHANGED
|
@@ -15,6 +15,8 @@ exports.removeTestUser = removeTestUser;
|
|
|
15
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
16
16
|
var _btoa = _interopRequireDefault(require("btoa"));
|
|
17
17
|
var _httpCore = require("@webex/http-core");
|
|
18
|
+
var _nodeRandomName = _interopRequireDefault(require("node-random-name"));
|
|
19
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
18
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; }
|
|
19
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
|
/**
|
|
@@ -102,8 +104,8 @@ function createTestUser() {
|
|
|
102
104
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
103
105
|
var clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
104
106
|
var clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
105
|
-
var machineAccount = options.machineAccount || process.env.WHISTLER_MACHINE_ACCOUNT;
|
|
106
|
-
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*");
|
|
107
109
|
var idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;
|
|
108
110
|
var orgId = options.orgId || process.env.WHISTLER_TEST_ORG_ID;
|
|
109
111
|
var whistlerServiceUrl = options.whistlerServiceUrl || process.env.WHISTLER_API_SERVICE_URL;
|
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,\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 ${options.token}`,\n },\n uri: options.reservationUrl,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAC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,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"}
|
|
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","randomName","WHISTLER_MACHINE_PASSWORD","uuid","v4","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';\nimport randomName from 'node-random-name';\nimport uuid from 'uuid';\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 =\n options.machineAccount || process.env.WHISTLER_MACHINE_ACCOUNT || randomName();\n const machinePassword =\n options.machinePassword || process.env.WHISTLER_MACHINE_PASSWORD || `${uuid.v4()}zAY1*`;\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 ${options.token}`,\n },\n uri: options.reservationUrl,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAAwB;AAAA;AAExB;AACA;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,CAAC,CAAC;EACzC,OAAO,IAAAvB,iBAAO,EAAC;IACbC,MAAM,EAAE,QAAQ;IAChBgB,OAAO,EAAE;MACPC,aAAa,mBAAYK,OAAO,CAACyB,KAAK;IACxC,CAAC;IACD9C,GAAG,EAAEqB,OAAO,CAAC2B;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.261",
|
|
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.261",
|
|
28
|
+
"@webex/test-helper-mocha": "3.0.0-beta.261",
|
|
29
|
+
"@webex/test-users": "3.0.0-beta.261",
|
|
30
30
|
"btoa": "^1.2.1",
|
|
31
31
|
"lodash": "^4.17.21",
|
|
32
32
|
"node-random-name": "^1.0.1",
|
package/src/index.js
CHANGED
package/src/whistler.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import btoa from 'btoa';
|
|
2
2
|
import {request} from '@webex/http-core';
|
|
3
|
+
import randomName from 'node-random-name';
|
|
4
|
+
import uuid from 'uuid';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Fetches credentials/access_token to talk to the whistler endpoint
|
|
@@ -85,8 +87,10 @@ const getClientCredentials = ({
|
|
|
85
87
|
export default function createTestUser(options = {}) {
|
|
86
88
|
const clientId = options.clientId || process.env.WEBEX_CLIENT_ID;
|
|
87
89
|
const clientSecret = options.clientSecret || process.env.WEBEX_CLIENT_SECRET;
|
|
88
|
-
const machineAccount =
|
|
89
|
-
|
|
90
|
+
const machineAccount =
|
|
91
|
+
options.machineAccount || process.env.WHISTLER_MACHINE_ACCOUNT || randomName();
|
|
92
|
+
const machinePassword =
|
|
93
|
+
options.machinePassword || process.env.WHISTLER_MACHINE_PASSWORD || `${uuid.v4()}zAY1*`;
|
|
90
94
|
const idbrokerUrl = options.idbrokerUrl || process.env.IDBROKER_BASE_URL;
|
|
91
95
|
const orgId = options.orgId || process.env.WHISTLER_TEST_ORG_ID;
|
|
92
96
|
const whistlerServiceUrl = options.whistlerServiceUrl || process.env.WHISTLER_API_SERVICE_URL;
|