@webex/internal-plugin-dss 2.22.0
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 +74 -0
- package/dist/constants.js +32 -0
- package/dist/constants.js.map +1 -0
- package/dist/dss.js +291 -0
- package/dist/dss.js.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -0
- package/src/constants.ts +14 -0
- package/src/dss.ts +255 -0
- package/src/index.ts +7 -0
- package/src/types.ts +25 -0
- package/test/unit/spec/dss.ts +363 -0
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @webex/internal-plugin-dss
|
|
2
|
+
|
|
3
|
+
[](https://github.com/RichardLitt/standard-readme)
|
|
4
|
+
|
|
5
|
+
> Plugin for Directory Search Service (DSS)
|
|
6
|
+
|
|
7
|
+
This is an internal Cisco Webex plugin. As such, it does not strictly adhere to semantic versioning. Use at your own risk. If you're not working on one of our first party clients, please look at our [developer api](https://developer.webex.com/) and stick to our public plugins.
|
|
8
|
+
|
|
9
|
+
- [Install](#install)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [Maintainers](#maintainers)
|
|
12
|
+
- [Contribute](#contribute)
|
|
13
|
+
- [License](#license)
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install --save @webex/internal-plugin-dss
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import '@webex/internal-plugin-dss';
|
|
25
|
+
|
|
26
|
+
import WebexCore from '@webex/webex-core';
|
|
27
|
+
|
|
28
|
+
const webex = new WebexCore();
|
|
29
|
+
|
|
30
|
+
// Namespace.
|
|
31
|
+
webex.internal.dss
|
|
32
|
+
|
|
33
|
+
// Register the plugin (connects to mercury).
|
|
34
|
+
webex.internal.dss.register()
|
|
35
|
+
.then(() => {}) // On successful registration.
|
|
36
|
+
.catch(() => {}); // On failed registration.
|
|
37
|
+
|
|
38
|
+
// Unregister the plugin (disconnects from mercury).
|
|
39
|
+
webex.internal.dss.unregister()
|
|
40
|
+
.then(() => {}) // On successful unregistration.
|
|
41
|
+
.catch(() => {}); // On failed unregistration.
|
|
42
|
+
|
|
43
|
+
// Methods
|
|
44
|
+
|
|
45
|
+
// Get detailed information on an entity
|
|
46
|
+
webex.internal.dss.lookupDetail({id: <entity-uuid>}).then((results) => {})
|
|
47
|
+
|
|
48
|
+
// Get information on multiple identities
|
|
49
|
+
webex.internal.dss.lookup({ids: [<entity-uuid-1>, <entity-uuid-2>]}).then((results) => {})
|
|
50
|
+
|
|
51
|
+
// Get information on entities by querying their email addresses
|
|
52
|
+
webex.internal.dss.lookupByEmail(
|
|
53
|
+
{emails: ['email1@example.com', 'email2@example.com']}
|
|
54
|
+
).then((results) => {})
|
|
55
|
+
|
|
56
|
+
// Search for information on certain type(s)
|
|
57
|
+
webex.internal.dss.search({
|
|
58
|
+
requestedTypes: [PERSON],
|
|
59
|
+
queryString: 'a name',
|
|
60
|
+
resultSize: 10,
|
|
61
|
+
}).then((results) => {})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Maintainers
|
|
65
|
+
|
|
66
|
+
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
67
|
+
|
|
68
|
+
## Contribute
|
|
69
|
+
|
|
70
|
+
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
© 2016-2022 Cisco and/or its affiliates. All Rights Reserved.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
exports.SEARCH_TYPES = exports.DSS_UNREGISTERED = exports.DSS_SERVICE_NAME = exports.DSS_SEARCH_MERCURY_EVENT = exports.DSS_RESULT = exports.DSS_REGISTERED = exports.DSS_LOOKUP_RESULT = exports.DSS_LOOKUP_MERCURY_EVENT = void 0;
|
|
10
|
+
var DSS_REGISTERED = 'dss:registered';
|
|
11
|
+
exports.DSS_REGISTERED = DSS_REGISTERED;
|
|
12
|
+
var DSS_UNREGISTERED = 'dss:unregistered';
|
|
13
|
+
exports.DSS_UNREGISTERED = DSS_UNREGISTERED;
|
|
14
|
+
var DSS_LOOKUP_MERCURY_EVENT = 'event:directory.lookup';
|
|
15
|
+
exports.DSS_LOOKUP_MERCURY_EVENT = DSS_LOOKUP_MERCURY_EVENT;
|
|
16
|
+
var DSS_SEARCH_MERCURY_EVENT = 'event:directory.search';
|
|
17
|
+
exports.DSS_SEARCH_MERCURY_EVENT = DSS_SEARCH_MERCURY_EVENT;
|
|
18
|
+
var DSS_LOOKUP_RESULT = 'dss:lookup.result';
|
|
19
|
+
exports.DSS_LOOKUP_RESULT = DSS_LOOKUP_RESULT;
|
|
20
|
+
var DSS_RESULT = 'dss:result';
|
|
21
|
+
exports.DSS_RESULT = DSS_RESULT;
|
|
22
|
+
var DSS_SERVICE_NAME = 'directorySearch';
|
|
23
|
+
exports.DSS_SERVICE_NAME = DSS_SERVICE_NAME;
|
|
24
|
+
var SEARCH_TYPES = {
|
|
25
|
+
PERSON: 'PERSON',
|
|
26
|
+
CALLING_SERVICE: 'CALLING_SERVICE',
|
|
27
|
+
EXTERNAL_CALLING: 'EXTERNAL_CALLING',
|
|
28
|
+
ROOM: 'ROOM',
|
|
29
|
+
ROBOT: 'ROBOT'
|
|
30
|
+
};
|
|
31
|
+
exports.SEARCH_TYPES = SEARCH_TYPES;
|
|
32
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DSS_REGISTERED","DSS_UNREGISTERED","DSS_LOOKUP_MERCURY_EVENT","DSS_SEARCH_MERCURY_EVENT","DSS_LOOKUP_RESULT","DSS_RESULT","DSS_SERVICE_NAME","SEARCH_TYPES","PERSON","CALLING_SERVICE","EXTERNAL_CALLING","ROOM","ROBOT"],"sources":["constants.ts"],"sourcesContent":["export const DSS_REGISTERED = 'dss:registered';\nexport const DSS_UNREGISTERED = 'dss:unregistered';\nexport const DSS_LOOKUP_MERCURY_EVENT = 'event:directory.lookup';\nexport const DSS_SEARCH_MERCURY_EVENT = 'event:directory.search';\nexport const DSS_LOOKUP_RESULT = 'dss:lookup.result';\nexport const DSS_RESULT = 'dss:result';\nexport const DSS_SERVICE_NAME = 'directorySearch';\nexport const SEARCH_TYPES = {\n PERSON: 'PERSON',\n CALLING_SERVICE: 'CALLING_SERVICE',\n EXTERNAL_CALLING: 'EXTERNAL_CALLING',\n ROOM: 'ROOM',\n ROBOT: 'ROBOT',\n};\n"],"mappings":";;;;;;;;;AAAO,IAAMA,cAAc,GAAG,gBAAvB;;AACA,IAAMC,gBAAgB,GAAG,kBAAzB;;AACA,IAAMC,wBAAwB,GAAG,wBAAjC;;AACA,IAAMC,wBAAwB,GAAG,wBAAjC;;AACA,IAAMC,iBAAiB,GAAG,mBAA1B;;AACA,IAAMC,UAAU,GAAG,YAAnB;;AACA,IAAMC,gBAAgB,GAAG,iBAAzB;;AACA,IAAMC,YAAY,GAAG;EAC1BC,MAAM,EAAE,QADkB;EAE1BC,eAAe,EAAE,iBAFS;EAG1BC,gBAAgB,EAAE,kBAHQ;EAI1BC,IAAI,EAAE,MAJoB;EAK1BC,KAAK,EAAE;AALmB,CAArB"}
|
package/dist/dss.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$keys2 = require("@babel/runtime-corejs2/core-js/object/keys");
|
|
4
|
+
|
|
5
|
+
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
|
|
6
|
+
|
|
7
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
|
|
8
|
+
|
|
9
|
+
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
|
|
10
|
+
|
|
11
|
+
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
|
|
12
|
+
|
|
13
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
14
|
+
|
|
15
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
16
|
+
|
|
17
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
18
|
+
value: true
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
exports.default = void 0;
|
|
22
|
+
|
|
23
|
+
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
24
|
+
|
|
25
|
+
var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
|
|
26
|
+
|
|
27
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
28
|
+
|
|
29
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
|
|
30
|
+
|
|
31
|
+
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
32
|
+
|
|
33
|
+
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
34
|
+
|
|
35
|
+
var _range2 = _interopRequireDefault(require("lodash/range"));
|
|
36
|
+
|
|
37
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
38
|
+
|
|
39
|
+
var _webexCore = require("@webex/webex-core");
|
|
40
|
+
|
|
41
|
+
require("@webex/internal-plugin-mercury");
|
|
42
|
+
|
|
43
|
+
var _constants = require("./constants");
|
|
44
|
+
|
|
45
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys2(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; }
|
|
46
|
+
|
|
47
|
+
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; }
|
|
48
|
+
|
|
49
|
+
var DSS = _webexCore.WebexPlugin.extend({
|
|
50
|
+
namespace: 'DSS',
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* registered value indicating events registration is successful
|
|
54
|
+
* @instance
|
|
55
|
+
* @type {Boolean}
|
|
56
|
+
* @memberof DSS
|
|
57
|
+
*/
|
|
58
|
+
registered: false,
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Explicitly sets up the DSS plugin by connecting to mercury, and listening for DSS events.
|
|
62
|
+
* @returns {Promise}
|
|
63
|
+
* @public
|
|
64
|
+
* @memberof DSS
|
|
65
|
+
*/
|
|
66
|
+
register: function register() {
|
|
67
|
+
var _this = this;
|
|
68
|
+
|
|
69
|
+
if (!this.webex.canAuthorize) {
|
|
70
|
+
this.logger.error('DSS->register#ERROR, Unable to register, SDK cannot authorize');
|
|
71
|
+
return _promise.default.reject(new Error('SDK cannot authorize'));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (this.registered) {
|
|
75
|
+
this.logger.info('dss->register#INFO, DSS plugin already registered');
|
|
76
|
+
return _promise.default.resolve();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return this.webex.internal.mercury.connect().then(function () {
|
|
80
|
+
_this.listenForEvents();
|
|
81
|
+
|
|
82
|
+
_this.trigger(_constants.DSS_REGISTERED);
|
|
83
|
+
|
|
84
|
+
_this.registered = true;
|
|
85
|
+
}).catch(function (error) {
|
|
86
|
+
_this.logger.error("DSS->register#ERROR, Unable to register, ".concat(error.message));
|
|
87
|
+
|
|
88
|
+
return _promise.default.reject(error);
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Explicitly tears down the DSS plugin by disconnecting from mercury, and stops listening to DSS events
|
|
94
|
+
* @returns {Promise}
|
|
95
|
+
* @public
|
|
96
|
+
* @memberof DSS
|
|
97
|
+
*/
|
|
98
|
+
unregister: function unregister() {
|
|
99
|
+
var _this2 = this;
|
|
100
|
+
|
|
101
|
+
if (!this.registered) {
|
|
102
|
+
this.logger.info('DSS->unregister#INFO, DSS plugin already unregistered');
|
|
103
|
+
return _promise.default.resolve();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.stopListeningForEvents();
|
|
107
|
+
return this.webex.internal.mercury.disconnect().then(function () {
|
|
108
|
+
_this2.trigger(_constants.DSS_UNREGISTERED);
|
|
109
|
+
|
|
110
|
+
_this2.registered = false;
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* registers for DSS events through mercury
|
|
116
|
+
* @returns {undefined}
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
listenForEvents: function listenForEvents() {
|
|
120
|
+
var _this3 = this;
|
|
121
|
+
|
|
122
|
+
this.webex.internal.mercury.on(_constants.DSS_LOOKUP_MERCURY_EVENT, function (envelope) {
|
|
123
|
+
_this3._handleEvent(envelope.data);
|
|
124
|
+
});
|
|
125
|
+
this.webex.internal.mercury.on(_constants.DSS_SEARCH_MERCURY_EVENT, function (envelope) {
|
|
126
|
+
_this3._handleEvent(envelope.data);
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* unregisteres all the DSS events from mercury
|
|
132
|
+
* @returns {undefined}
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
135
|
+
stopListeningForEvents: function stopListeningForEvents() {
|
|
136
|
+
this.webex.internal.mercury.off(_constants.DSS_LOOKUP_MERCURY_EVENT);
|
|
137
|
+
this.webex.internal.mercury.off(_constants.DSS_SEARCH_MERCURY_EVENT);
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {UUID} requestId the id of the request
|
|
142
|
+
* @returns {string}
|
|
143
|
+
*/
|
|
144
|
+
_getResultEventName: function _getResultEventName(requestId) {
|
|
145
|
+
return "".concat(_constants.DSS_RESULT).concat(requestId);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {Object} data the event data
|
|
150
|
+
* @returns {undefined}
|
|
151
|
+
*/
|
|
152
|
+
_handleEvent: function _handleEvent(data) {
|
|
153
|
+
this.trigger(this._getResultEventName(data.requestId), data);
|
|
154
|
+
this.trigger(_constants.DSS_LOOKUP_RESULT, data);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Makes the request to the directory service
|
|
159
|
+
* @param {Object} options
|
|
160
|
+
* @param {string} options.resource the URL to query
|
|
161
|
+
* @param {string} options.params additional params for the body of the request
|
|
162
|
+
* @param {string} options.dataPath to path to get the data in the result object
|
|
163
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
164
|
+
*/
|
|
165
|
+
_request: function _request(options) {
|
|
166
|
+
var _this4 = this;
|
|
167
|
+
|
|
168
|
+
var resource = options.resource,
|
|
169
|
+
params = options.params,
|
|
170
|
+
dataPath = options.dataPath;
|
|
171
|
+
|
|
172
|
+
var requestId = _uuid.default.v4();
|
|
173
|
+
|
|
174
|
+
var eventName = this._getResultEventName(requestId);
|
|
175
|
+
|
|
176
|
+
var result = {};
|
|
177
|
+
var expectedSeqNums;
|
|
178
|
+
return new _promise.default(function (resolve) {
|
|
179
|
+
_this4.listenTo(_this4, eventName, function (data) {
|
|
180
|
+
var resultData = (0, _get2.default)(data, dataPath);
|
|
181
|
+
result[data.sequence] = resultData;
|
|
182
|
+
|
|
183
|
+
if (data.finished) {
|
|
184
|
+
expectedSeqNums = (0, _range2.default)(data.sequence + 1).map(String);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var done = (0, _isEqual2.default)(expectedSeqNums, (0, _keys.default)(result));
|
|
188
|
+
|
|
189
|
+
if (done) {
|
|
190
|
+
var resultArray = [];
|
|
191
|
+
expectedSeqNums.forEach(function (index) {
|
|
192
|
+
var seqResult = result[index];
|
|
193
|
+
|
|
194
|
+
if (seqResult) {
|
|
195
|
+
resultArray.push.apply(resultArray, (0, _toConsumableArray2.default)(seqResult));
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
resolve(resultArray);
|
|
199
|
+
|
|
200
|
+
_this4.stopListening(_this4, eventName);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
_this4.webex.request({
|
|
205
|
+
service: _constants.DSS_SERVICE_NAME,
|
|
206
|
+
resource: resource,
|
|
207
|
+
method: 'POST',
|
|
208
|
+
contentType: 'application/json',
|
|
209
|
+
body: _objectSpread({
|
|
210
|
+
requestId: requestId
|
|
211
|
+
}, params)
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Retrieves detailed information about an entity
|
|
218
|
+
* @param {Object} options
|
|
219
|
+
* @param {UUID} options.id the id of the entity to lookup
|
|
220
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
221
|
+
*/
|
|
222
|
+
lookupDetail: function lookupDetail(options) {
|
|
223
|
+
var id = options.id;
|
|
224
|
+
return this._request({
|
|
225
|
+
dataPath: 'lookupResult.entities',
|
|
226
|
+
resource: "/lookup/orgid/".concat(this.webex.internal.device.orgId, "/identity/").concat(id, "/detail")
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Retrieves basic information about a list entities within an organization
|
|
232
|
+
* @param {Object} options
|
|
233
|
+
* @param {UUID} options.ids the id of the entity to lookup
|
|
234
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
235
|
+
*/
|
|
236
|
+
lookup: function lookup(options) {
|
|
237
|
+
var ids = options.ids;
|
|
238
|
+
return this._request({
|
|
239
|
+
dataPath: 'lookupResult.entities',
|
|
240
|
+
resource: "/lookup/orgid/".concat(this.webex.internal.device.orgId, "/identities"),
|
|
241
|
+
params: {
|
|
242
|
+
lookupValues: ids
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Retrieves basic information about a list entities within an organization
|
|
249
|
+
* @param {Object} options
|
|
250
|
+
* @param {UUID} options.emails the emails of the entities to lookup
|
|
251
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
252
|
+
*/
|
|
253
|
+
lookupByEmail: function lookupByEmail(options) {
|
|
254
|
+
var emails = options.emails;
|
|
255
|
+
return this._request({
|
|
256
|
+
dataPath: 'lookupResult.entities',
|
|
257
|
+
resource: "/lookup/orgid/".concat(this.webex.internal.device.orgId, "/emails"),
|
|
258
|
+
params: {
|
|
259
|
+
lookupValues: emails
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Search for information about entities
|
|
266
|
+
* @param {Object} options
|
|
267
|
+
* @param {SearchType[]} options.requestedTypes an array of search types from: PERSON, CALLING_SERVICE, EXTERNAL_CALLING, ROOM, ROBOT
|
|
268
|
+
* @param {string[]} options.queryString A query string that will be transformed into a Directory search filter query. It is used to search the following fields: username, givenName, familyName, displayName and email
|
|
269
|
+
* @param {number} options.resultSize The maximum number of results returned from each provider
|
|
270
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
271
|
+
*/
|
|
272
|
+
search: function search(options) {
|
|
273
|
+
var requestedTypes = options.requestedTypes,
|
|
274
|
+
resultSize = options.resultSize,
|
|
275
|
+
queryString = options.queryString;
|
|
276
|
+
return this._request({
|
|
277
|
+
dataPath: 'directoryEntities',
|
|
278
|
+
resource: "/search/orgid/".concat(this.webex.internal.device.orgId, "/entities"),
|
|
279
|
+
params: {
|
|
280
|
+
queryString: queryString,
|
|
281
|
+
resultSize: resultSize,
|
|
282
|
+
requestedTypes: requestedTypes
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
},
|
|
286
|
+
version: "2.22.0"
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
var _default = DSS;
|
|
290
|
+
exports.default = _default;
|
|
291
|
+
//# sourceMappingURL=dss.js.map
|
package/dist/dss.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DSS","WebexPlugin","extend","namespace","registered","register","webex","canAuthorize","logger","error","reject","Error","info","resolve","internal","mercury","connect","then","listenForEvents","trigger","DSS_REGISTERED","catch","message","unregister","stopListeningForEvents","disconnect","DSS_UNREGISTERED","on","DSS_LOOKUP_MERCURY_EVENT","envelope","_handleEvent","data","DSS_SEARCH_MERCURY_EVENT","off","_getResultEventName","requestId","DSS_RESULT","DSS_LOOKUP_RESULT","_request","options","resource","params","dataPath","uuid","v4","eventName","result","expectedSeqNums","listenTo","resultData","sequence","finished","map","String","done","resultArray","forEach","index","seqResult","push","stopListening","request","service","DSS_SERVICE_NAME","method","contentType","body","lookupDetail","id","device","orgId","lookup","ids","lookupValues","lookupByEmail","emails","search","requestedTypes","resultSize","queryString"],"sources":["dss.ts"],"sourcesContent":["/* eslint-disable no-underscore-dangle */\n/*!\n * Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.\n */\nimport uuid from 'uuid';\nimport {WebexPlugin} from '@webex/webex-core';\nimport '@webex/internal-plugin-mercury';\nimport {range, isEqual, get} from 'lodash';\nimport type {SearchOptions, LookupDetailOptions, LookupOptions, LookupByEmailOptions} from './types';\n\nimport {\n DSS_REGISTERED,\n DSS_UNREGISTERED,\n DSS_LOOKUP_MERCURY_EVENT,\n DSS_LOOKUP_RESULT,\n DSS_SERVICE_NAME,\n DSS_SEARCH_MERCURY_EVENT,\n DSS_RESULT,\n} from './constants';\n\nconst DSS = WebexPlugin.extend({\n namespace: 'DSS',\n\n /**\n * registered value indicating events registration is successful\n * @instance\n * @type {Boolean}\n * @memberof DSS\n */\n registered: false,\n\n /**\n * Explicitly sets up the DSS plugin by connecting to mercury, and listening for DSS events.\n * @returns {Promise}\n * @public\n * @memberof DSS\n */\n register() {\n if (!this.webex.canAuthorize) {\n this.logger.error('DSS->register#ERROR, Unable to register, SDK cannot authorize');\n\n return Promise.reject(new Error('SDK cannot authorize'));\n }\n\n if (this.registered) {\n this.logger.info('dss->register#INFO, DSS plugin already registered');\n\n return Promise.resolve();\n }\n\n return this.webex.internal.mercury.connect()\n .then(() => {\n this.listenForEvents();\n this.trigger(DSS_REGISTERED);\n this.registered = true;\n })\n .catch((error) => {\n this.logger.error(`DSS->register#ERROR, Unable to register, ${error.message}`);\n\n return Promise.reject(error);\n });\n },\n\n /**\n * Explicitly tears down the DSS plugin by disconnecting from mercury, and stops listening to DSS events\n * @returns {Promise}\n * @public\n * @memberof DSS\n */\n unregister() {\n if (!this.registered) {\n this.logger.info('DSS->unregister#INFO, DSS plugin already unregistered');\n\n return Promise.resolve();\n }\n\n this.stopListeningForEvents();\n\n return this.webex.internal.mercury.disconnect()\n .then(() => {\n this.trigger(DSS_UNREGISTERED);\n this.registered = false;\n });\n },\n\n /**\n * registers for DSS events through mercury\n * @returns {undefined}\n * @private\n */\n listenForEvents() {\n this.webex.internal.mercury.on(DSS_LOOKUP_MERCURY_EVENT, (envelope) => {\n this._handleEvent(envelope.data);\n });\n this.webex.internal.mercury.on(DSS_SEARCH_MERCURY_EVENT, (envelope) => {\n this._handleEvent(envelope.data);\n });\n },\n\n /**\n * unregisteres all the DSS events from mercury\n * @returns {undefined}\n * @private\n */\n stopListeningForEvents() {\n this.webex.internal.mercury.off(DSS_LOOKUP_MERCURY_EVENT);\n this.webex.internal.mercury.off(DSS_SEARCH_MERCURY_EVENT);\n },\n\n /**\n * @param {UUID} requestId the id of the request\n * @returns {string}\n */\n _getResultEventName(requestId) {\n return `${DSS_RESULT}${requestId}`;\n },\n\n /**\n * @param {Object} data the event data\n * @returns {undefined}\n */\n _handleEvent(data) {\n this.trigger(this._getResultEventName(data.requestId), data);\n this.trigger(DSS_LOOKUP_RESULT, data);\n },\n\n /**\n * Makes the request to the directory service\n * @param {Object} options\n * @param {string} options.resource the URL to query\n * @param {string} options.params additional params for the body of the request\n * @param {string} options.dataPath to path to get the data in the result object\n * @returns {Promise} Resolves with an array of entities found\n */\n _request(options) {\n const {resource, params, dataPath} = options;\n\n const requestId = uuid.v4();\n const eventName = this._getResultEventName(requestId);\n const result = {};\n let expectedSeqNums;\n\n return new Promise((resolve) => {\n this.listenTo(this, eventName, (data) => {\n const resultData = get(data, dataPath);\n\n result[data.sequence] = resultData;\n\n if (data.finished) {\n expectedSeqNums = range(data.sequence + 1).map(String);\n }\n\n const done = isEqual(expectedSeqNums, Object.keys(result));\n\n if (done) {\n const resultArray = [];\n expectedSeqNums.forEach((index) => {\n const seqResult = result[index];\n if (seqResult) {\n resultArray.push(...seqResult);\n }\n })\n\n resolve(resultArray);\n this.stopListening(this, eventName);\n }\n });\n this.webex.request({\n service: DSS_SERVICE_NAME,\n resource,\n method: 'POST',\n contentType: 'application/json',\n body: {requestId, ...params}\n });\n });\n },\n\n /**\n * Retrieves detailed information about an entity\n * @param {Object} options\n * @param {UUID} options.id the id of the entity to lookup\n * @returns {Promise} Resolves with an array of entities found\n */\n lookupDetail(options: LookupDetailOptions) {\n const {id} = options;\n\n return this._request({\n dataPath: 'lookupResult.entities',\n resource: `/lookup/orgid/${this.webex.internal.device.orgId}/identity/${id}/detail`\n });\n },\n\n /**\n * Retrieves basic information about a list entities within an organization\n * @param {Object} options\n * @param {UUID} options.ids the id of the entity to lookup\n * @returns {Promise} Resolves with an array of entities found\n */\n lookup(options: LookupOptions) {\n const {ids} = options;\n\n return this._request({\n dataPath: 'lookupResult.entities',\n resource: `/lookup/orgid/${this.webex.internal.device.orgId}/identities`,\n params: {\n lookupValues: ids,\n }\n });\n },\n\n /**\n * Retrieves basic information about a list entities within an organization\n * @param {Object} options\n * @param {UUID} options.emails the emails of the entities to lookup\n * @returns {Promise} Resolves with an array of entities found\n */\n lookupByEmail(options: LookupByEmailOptions) {\n const {emails} = options;\n\n return this._request({\n dataPath: 'lookupResult.entities',\n resource: `/lookup/orgid/${this.webex.internal.device.orgId}/emails`,\n params: {\n lookupValues: emails,\n }\n });\n },\n\n /**\n * Search for information about entities\n * @param {Object} options\n * @param {SearchType[]} options.requestedTypes an array of search types from: PERSON, CALLING_SERVICE, EXTERNAL_CALLING, ROOM, ROBOT\n * @param {string[]} options.queryString A query string that will be transformed into a Directory search filter query. It is used to search the following fields: username, givenName, familyName, displayName and email\n * @param {number} options.resultSize The maximum number of results returned from each provider\n * @returns {Promise} Resolves with an array of entities found\n */\n search(options: SearchOptions) {\n const {\n requestedTypes, resultSize, queryString\n } = options;\n\n return this._request({\n dataPath: 'directoryEntities',\n resource: `/search/orgid/${this.webex.internal.device.orgId}/entities`,\n params: {\n queryString,\n resultSize,\n requestedTypes\n }\n });\n }\n\n});\n\nexport default DSS;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;AACA;;AACA;;AAIA;;;;;;AAUA,IAAMA,GAAG,GAAGC,sBAAA,CAAYC,MAAZ,CAAmB;EAC7BC,SAAS,EAAE,KADkB;;EAG7B;AACF;AACA;AACA;AACA;AACA;EACEC,UAAU,EAAE,KATiB;;EAW7B;AACF;AACA;AACA;AACA;AACA;EACEC,QAjB6B,sBAiBlB;IAAA;;IACT,IAAI,CAAC,KAAKC,KAAL,CAA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uD,MAApB,CAA2BC,KAA9C,cAFW;MAGnB7B,MAAM,EAAE;QACNsC,WAAW,EAAXA,WADM;QAEND,UAAU,EAAVA,UAFM;QAGND,cAAc,EAAdA;MAHM;IAHW,CAAd,CAAP;EASD,CAtO4B;EAAA;AAAA,CAAnB,CAAZ;;eA0Oe7E,G"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
_Object$defineProperty(exports, "default", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function get() {
|
|
14
|
+
return _dss.default;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
var _webexCore = require("@webex/webex-core");
|
|
19
|
+
|
|
20
|
+
var _dss = _interopRequireDefault(require("./dss"));
|
|
21
|
+
|
|
22
|
+
(0, _webexCore.registerInternalPlugin)('dss', _dss.default);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registerInternalPlugin","DSS"],"sources":["index.ts"],"sourcesContent":["import {registerInternalPlugin} from '@webex/webex-core';\n\nimport DSS from './dss';\n\nregisterInternalPlugin('dss', DSS);\n\nexport {default} from './dss';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AAEA;;AAEA,IAAAA,iCAAA,EAAuB,KAAvB,EAA8BC,YAA9B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
exports.SearchType = void 0;
|
|
10
|
+
var SearchType;
|
|
11
|
+
exports.SearchType = SearchType;
|
|
12
|
+
|
|
13
|
+
(function (SearchType) {
|
|
14
|
+
SearchType["PERSON"] = "PERSON";
|
|
15
|
+
SearchType["CALLING_SERVICE"] = "CALLING_SERVICE";
|
|
16
|
+
SearchType["EXTERNAL_CALLING"] = "EXTERNAL_CALLING";
|
|
17
|
+
SearchType["ROOM"] = "ROOM";
|
|
18
|
+
SearchType["ROBOT"] = "ROBOT";
|
|
19
|
+
})(SearchType || (exports.SearchType = SearchType = {}));
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SearchType"],"sources":["types.ts"],"sourcesContent":["export interface LookupDetailOptions {\n id: string;\n}\n\nexport interface LookupOptions {\n ids: string[];\n}\n\nexport interface LookupByEmailOptions {\n emails: string[];\n}\n\nexport enum SearchType {\n PERSON = 'PERSON', \n CALLING_SERVICE = 'CALLING_SERVICE',\n EXTERNAL_CALLING = 'EXTERNAL_CALLING',\n ROOM = 'ROOM',\n ROBOT = 'ROBOT'\n}\n\nexport interface SearchOptions {\n requestedTypes: SearchType[],\n resultSize: number,\n queryString: string,\n}\n"],"mappings":";;;;;;;;;IAYYA,U;;;WAAAA,U;EAAAA,U;EAAAA,U;EAAAA,U;EAAAA,U;EAAAA,U;GAAAA,U,0BAAAA,U"}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webex/internal-plugin-dss",
|
|
3
|
+
"version": "2.22.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Colin Read <coread@cisco.com>",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"devMain": "src/index.ts",
|
|
9
|
+
"repository": "https://github.com/webex/webex-js-sdk/tree/master/packages/node_modules/@webex/internal-plugin-dss",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=8"
|
|
12
|
+
},
|
|
13
|
+
"browserify": {
|
|
14
|
+
"transform": [
|
|
15
|
+
"envify"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@babel/runtime-corejs2": "^7.14.8",
|
|
20
|
+
"@webex/webex-core": "2.22.0",
|
|
21
|
+
"lodash": "^4.17.21",
|
|
22
|
+
"uuid": "^3.3.2",
|
|
23
|
+
"@webex/internal-plugin-mercury": "2.22.0",
|
|
24
|
+
"envify": "^4.1.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const DSS_REGISTERED = 'dss:registered';
|
|
2
|
+
export const DSS_UNREGISTERED = 'dss:unregistered';
|
|
3
|
+
export const DSS_LOOKUP_MERCURY_EVENT = 'event:directory.lookup';
|
|
4
|
+
export const DSS_SEARCH_MERCURY_EVENT = 'event:directory.search';
|
|
5
|
+
export const DSS_LOOKUP_RESULT = 'dss:lookup.result';
|
|
6
|
+
export const DSS_RESULT = 'dss:result';
|
|
7
|
+
export const DSS_SERVICE_NAME = 'directorySearch';
|
|
8
|
+
export const SEARCH_TYPES = {
|
|
9
|
+
PERSON: 'PERSON',
|
|
10
|
+
CALLING_SERVICE: 'CALLING_SERVICE',
|
|
11
|
+
EXTERNAL_CALLING: 'EXTERNAL_CALLING',
|
|
12
|
+
ROOM: 'ROOM',
|
|
13
|
+
ROBOT: 'ROBOT',
|
|
14
|
+
};
|
package/src/dss.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
|
|
4
|
+
*/
|
|
5
|
+
import uuid from 'uuid';
|
|
6
|
+
import {WebexPlugin} from '@webex/webex-core';
|
|
7
|
+
import '@webex/internal-plugin-mercury';
|
|
8
|
+
import {range, isEqual, get} from 'lodash';
|
|
9
|
+
import type {SearchOptions, LookupDetailOptions, LookupOptions, LookupByEmailOptions} from './types';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
DSS_REGISTERED,
|
|
13
|
+
DSS_UNREGISTERED,
|
|
14
|
+
DSS_LOOKUP_MERCURY_EVENT,
|
|
15
|
+
DSS_LOOKUP_RESULT,
|
|
16
|
+
DSS_SERVICE_NAME,
|
|
17
|
+
DSS_SEARCH_MERCURY_EVENT,
|
|
18
|
+
DSS_RESULT,
|
|
19
|
+
} from './constants';
|
|
20
|
+
|
|
21
|
+
const DSS = WebexPlugin.extend({
|
|
22
|
+
namespace: 'DSS',
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* registered value indicating events registration is successful
|
|
26
|
+
* @instance
|
|
27
|
+
* @type {Boolean}
|
|
28
|
+
* @memberof DSS
|
|
29
|
+
*/
|
|
30
|
+
registered: false,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Explicitly sets up the DSS plugin by connecting to mercury, and listening for DSS events.
|
|
34
|
+
* @returns {Promise}
|
|
35
|
+
* @public
|
|
36
|
+
* @memberof DSS
|
|
37
|
+
*/
|
|
38
|
+
register() {
|
|
39
|
+
if (!this.webex.canAuthorize) {
|
|
40
|
+
this.logger.error('DSS->register#ERROR, Unable to register, SDK cannot authorize');
|
|
41
|
+
|
|
42
|
+
return Promise.reject(new Error('SDK cannot authorize'));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.registered) {
|
|
46
|
+
this.logger.info('dss->register#INFO, DSS plugin already registered');
|
|
47
|
+
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return this.webex.internal.mercury.connect()
|
|
52
|
+
.then(() => {
|
|
53
|
+
this.listenForEvents();
|
|
54
|
+
this.trigger(DSS_REGISTERED);
|
|
55
|
+
this.registered = true;
|
|
56
|
+
})
|
|
57
|
+
.catch((error) => {
|
|
58
|
+
this.logger.error(`DSS->register#ERROR, Unable to register, ${error.message}`);
|
|
59
|
+
|
|
60
|
+
return Promise.reject(error);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Explicitly tears down the DSS plugin by disconnecting from mercury, and stops listening to DSS events
|
|
66
|
+
* @returns {Promise}
|
|
67
|
+
* @public
|
|
68
|
+
* @memberof DSS
|
|
69
|
+
*/
|
|
70
|
+
unregister() {
|
|
71
|
+
if (!this.registered) {
|
|
72
|
+
this.logger.info('DSS->unregister#INFO, DSS plugin already unregistered');
|
|
73
|
+
|
|
74
|
+
return Promise.resolve();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this.stopListeningForEvents();
|
|
78
|
+
|
|
79
|
+
return this.webex.internal.mercury.disconnect()
|
|
80
|
+
.then(() => {
|
|
81
|
+
this.trigger(DSS_UNREGISTERED);
|
|
82
|
+
this.registered = false;
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* registers for DSS events through mercury
|
|
88
|
+
* @returns {undefined}
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
listenForEvents() {
|
|
92
|
+
this.webex.internal.mercury.on(DSS_LOOKUP_MERCURY_EVENT, (envelope) => {
|
|
93
|
+
this._handleEvent(envelope.data);
|
|
94
|
+
});
|
|
95
|
+
this.webex.internal.mercury.on(DSS_SEARCH_MERCURY_EVENT, (envelope) => {
|
|
96
|
+
this._handleEvent(envelope.data);
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* unregisteres all the DSS events from mercury
|
|
102
|
+
* @returns {undefined}
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
stopListeningForEvents() {
|
|
106
|
+
this.webex.internal.mercury.off(DSS_LOOKUP_MERCURY_EVENT);
|
|
107
|
+
this.webex.internal.mercury.off(DSS_SEARCH_MERCURY_EVENT);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {UUID} requestId the id of the request
|
|
112
|
+
* @returns {string}
|
|
113
|
+
*/
|
|
114
|
+
_getResultEventName(requestId) {
|
|
115
|
+
return `${DSS_RESULT}${requestId}`;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {Object} data the event data
|
|
120
|
+
* @returns {undefined}
|
|
121
|
+
*/
|
|
122
|
+
_handleEvent(data) {
|
|
123
|
+
this.trigger(this._getResultEventName(data.requestId), data);
|
|
124
|
+
this.trigger(DSS_LOOKUP_RESULT, data);
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Makes the request to the directory service
|
|
129
|
+
* @param {Object} options
|
|
130
|
+
* @param {string} options.resource the URL to query
|
|
131
|
+
* @param {string} options.params additional params for the body of the request
|
|
132
|
+
* @param {string} options.dataPath to path to get the data in the result object
|
|
133
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
134
|
+
*/
|
|
135
|
+
_request(options) {
|
|
136
|
+
const {resource, params, dataPath} = options;
|
|
137
|
+
|
|
138
|
+
const requestId = uuid.v4();
|
|
139
|
+
const eventName = this._getResultEventName(requestId);
|
|
140
|
+
const result = {};
|
|
141
|
+
let expectedSeqNums;
|
|
142
|
+
|
|
143
|
+
return new Promise((resolve) => {
|
|
144
|
+
this.listenTo(this, eventName, (data) => {
|
|
145
|
+
const resultData = get(data, dataPath);
|
|
146
|
+
|
|
147
|
+
result[data.sequence] = resultData;
|
|
148
|
+
|
|
149
|
+
if (data.finished) {
|
|
150
|
+
expectedSeqNums = range(data.sequence + 1).map(String);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const done = isEqual(expectedSeqNums, Object.keys(result));
|
|
154
|
+
|
|
155
|
+
if (done) {
|
|
156
|
+
const resultArray = [];
|
|
157
|
+
expectedSeqNums.forEach((index) => {
|
|
158
|
+
const seqResult = result[index];
|
|
159
|
+
if (seqResult) {
|
|
160
|
+
resultArray.push(...seqResult);
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
resolve(resultArray);
|
|
165
|
+
this.stopListening(this, eventName);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
this.webex.request({
|
|
169
|
+
service: DSS_SERVICE_NAME,
|
|
170
|
+
resource,
|
|
171
|
+
method: 'POST',
|
|
172
|
+
contentType: 'application/json',
|
|
173
|
+
body: {requestId, ...params}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Retrieves detailed information about an entity
|
|
180
|
+
* @param {Object} options
|
|
181
|
+
* @param {UUID} options.id the id of the entity to lookup
|
|
182
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
183
|
+
*/
|
|
184
|
+
lookupDetail(options: LookupDetailOptions) {
|
|
185
|
+
const {id} = options;
|
|
186
|
+
|
|
187
|
+
return this._request({
|
|
188
|
+
dataPath: 'lookupResult.entities',
|
|
189
|
+
resource: `/lookup/orgid/${this.webex.internal.device.orgId}/identity/${id}/detail`
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Retrieves basic information about a list entities within an organization
|
|
195
|
+
* @param {Object} options
|
|
196
|
+
* @param {UUID} options.ids the id of the entity to lookup
|
|
197
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
198
|
+
*/
|
|
199
|
+
lookup(options: LookupOptions) {
|
|
200
|
+
const {ids} = options;
|
|
201
|
+
|
|
202
|
+
return this._request({
|
|
203
|
+
dataPath: 'lookupResult.entities',
|
|
204
|
+
resource: `/lookup/orgid/${this.webex.internal.device.orgId}/identities`,
|
|
205
|
+
params: {
|
|
206
|
+
lookupValues: ids,
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Retrieves basic information about a list entities within an organization
|
|
213
|
+
* @param {Object} options
|
|
214
|
+
* @param {UUID} options.emails the emails of the entities to lookup
|
|
215
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
216
|
+
*/
|
|
217
|
+
lookupByEmail(options: LookupByEmailOptions) {
|
|
218
|
+
const {emails} = options;
|
|
219
|
+
|
|
220
|
+
return this._request({
|
|
221
|
+
dataPath: 'lookupResult.entities',
|
|
222
|
+
resource: `/lookup/orgid/${this.webex.internal.device.orgId}/emails`,
|
|
223
|
+
params: {
|
|
224
|
+
lookupValues: emails,
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Search for information about entities
|
|
231
|
+
* @param {Object} options
|
|
232
|
+
* @param {SearchType[]} options.requestedTypes an array of search types from: PERSON, CALLING_SERVICE, EXTERNAL_CALLING, ROOM, ROBOT
|
|
233
|
+
* @param {string[]} options.queryString A query string that will be transformed into a Directory search filter query. It is used to search the following fields: username, givenName, familyName, displayName and email
|
|
234
|
+
* @param {number} options.resultSize The maximum number of results returned from each provider
|
|
235
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
236
|
+
*/
|
|
237
|
+
search(options: SearchOptions) {
|
|
238
|
+
const {
|
|
239
|
+
requestedTypes, resultSize, queryString
|
|
240
|
+
} = options;
|
|
241
|
+
|
|
242
|
+
return this._request({
|
|
243
|
+
dataPath: 'directoryEntities',
|
|
244
|
+
resource: `/search/orgid/${this.webex.internal.device.orgId}/entities`,
|
|
245
|
+
params: {
|
|
246
|
+
queryString,
|
|
247
|
+
resultSize,
|
|
248
|
+
requestedTypes
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
export default DSS;
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface LookupDetailOptions {
|
|
2
|
+
id: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface LookupOptions {
|
|
6
|
+
ids: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface LookupByEmailOptions {
|
|
10
|
+
emails: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum SearchType {
|
|
14
|
+
PERSON = 'PERSON',
|
|
15
|
+
CALLING_SERVICE = 'CALLING_SERVICE',
|
|
16
|
+
EXTERNAL_CALLING = 'EXTERNAL_CALLING',
|
|
17
|
+
ROOM = 'ROOM',
|
|
18
|
+
ROBOT = 'ROBOT'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SearchOptions {
|
|
22
|
+
requestedTypes: SearchType[],
|
|
23
|
+
resultSize: number,
|
|
24
|
+
queryString: string,
|
|
25
|
+
}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { assert } from "@webex/test-helper-chai";
|
|
6
|
+
import DSS from "@webex/internal-plugin-dss";
|
|
7
|
+
import MockWebex from "@webex/test-helper-mock-webex";
|
|
8
|
+
import sinon from "sinon";
|
|
9
|
+
import { expect } from "chai";
|
|
10
|
+
import { set } from "lodash";
|
|
11
|
+
import uuid from "uuid";
|
|
12
|
+
|
|
13
|
+
describe("plugin-dss", () => {
|
|
14
|
+
describe("DSS", () => {
|
|
15
|
+
let webex;
|
|
16
|
+
let uuidStub;
|
|
17
|
+
let mercuryCallbacks;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
webex = new MockWebex({
|
|
21
|
+
canAuthorize: false,
|
|
22
|
+
children: {
|
|
23
|
+
dss: DSS,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
uuidStub = sinon.stub(uuid, "v4").returns("randomid");
|
|
28
|
+
|
|
29
|
+
webex.canAuthorize = true;
|
|
30
|
+
webex.internal.device.orgId = "userOrgId";
|
|
31
|
+
|
|
32
|
+
mercuryCallbacks = {};
|
|
33
|
+
|
|
34
|
+
webex.internal.mercury = {
|
|
35
|
+
connect: sinon.stub().returns(Promise.resolve()),
|
|
36
|
+
disconnect: sinon.stub().returns(Promise.resolve()),
|
|
37
|
+
on: sinon.stub().callsFake((event, callback) => {
|
|
38
|
+
mercuryCallbacks[event] = callback;
|
|
39
|
+
}),
|
|
40
|
+
off: sinon.spy(),
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
uuidStub.restore();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("#register()", () => {
|
|
49
|
+
it("registers correctly", async () => {
|
|
50
|
+
await webex.internal.dss.register();
|
|
51
|
+
|
|
52
|
+
assert.callCount(webex.internal.mercury.on, 2);
|
|
53
|
+
|
|
54
|
+
const firstCallArgs = webex.internal.mercury.on.getCall(0).args;
|
|
55
|
+
expect(firstCallArgs[0]).to.equal("event:directory.lookup");
|
|
56
|
+
expect(firstCallArgs[1]).to.be.a("function");
|
|
57
|
+
|
|
58
|
+
const secondCallArgs = webex.internal.mercury.on.getCall(1).args;
|
|
59
|
+
expect(secondCallArgs[0]).to.equal("event:directory.search");
|
|
60
|
+
expect(secondCallArgs[1]).to.be.a("function");
|
|
61
|
+
|
|
62
|
+
assert.equal(webex.internal.dss.registered, true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("rejects when it cannot authorize", async () => {
|
|
66
|
+
webex.canAuthorize = false;
|
|
67
|
+
await expect(webex.internal.dss.register()).to.be.rejectedWith(
|
|
68
|
+
Error,
|
|
69
|
+
"SDK cannot authorize"
|
|
70
|
+
);
|
|
71
|
+
assert.equal(webex.internal.dss.registered, false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("#unregister()", () => {
|
|
76
|
+
it("unregisters correctly", async () => {
|
|
77
|
+
webex.internal.dss.registered = true;
|
|
78
|
+
await webex.internal.dss.unregister();
|
|
79
|
+
|
|
80
|
+
assert.callCount(webex.internal.mercury.off, 2);
|
|
81
|
+
|
|
82
|
+
const firstCallArgs = webex.internal.mercury.off.getCall(0).args;
|
|
83
|
+
expect(firstCallArgs[0]).to.equal("event:directory.lookup");
|
|
84
|
+
|
|
85
|
+
const secondCallArgs = webex.internal.mercury.off.getCall(1).args;
|
|
86
|
+
expect(secondCallArgs[0]).to.equal("event:directory.search");
|
|
87
|
+
|
|
88
|
+
assert.equal(webex.internal.dss.registered, false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("handles unregister when it is not registered", async () => {
|
|
92
|
+
const result = await webex.internal.dss.unregister();
|
|
93
|
+
await expect(result).equal(undefined);
|
|
94
|
+
assert.equal(webex.internal.dss.registered, false);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const createData = (requestId, sequence, finished, dataPath) => {
|
|
99
|
+
const data = {
|
|
100
|
+
requestId,
|
|
101
|
+
sequence,
|
|
102
|
+
};
|
|
103
|
+
if (finished) {
|
|
104
|
+
(data as any).finished = finished;
|
|
105
|
+
}
|
|
106
|
+
set(data, dataPath, [`data${sequence}`]);
|
|
107
|
+
return { data };
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const testRequest = async ({
|
|
111
|
+
method,
|
|
112
|
+
resource,
|
|
113
|
+
params,
|
|
114
|
+
bodyParams,
|
|
115
|
+
dataPath,
|
|
116
|
+
event,
|
|
117
|
+
}) => {
|
|
118
|
+
webex.request = sinon.stub();
|
|
119
|
+
|
|
120
|
+
await webex.internal.dss.register();
|
|
121
|
+
|
|
122
|
+
const promise = webex.internal.dss[method](params);
|
|
123
|
+
|
|
124
|
+
const requestId = "randomid";
|
|
125
|
+
|
|
126
|
+
expect(webex.request.getCall(0).args).to.deep.equal([
|
|
127
|
+
{
|
|
128
|
+
service: "directorySearch",
|
|
129
|
+
body: {
|
|
130
|
+
requestId,
|
|
131
|
+
...bodyParams,
|
|
132
|
+
},
|
|
133
|
+
contentType: "application/json",
|
|
134
|
+
method: "POST",
|
|
135
|
+
resource,
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
mercuryCallbacks[event](createData(requestId, 1, false, dataPath));
|
|
140
|
+
mercuryCallbacks[event](createData(requestId, 2, true, dataPath));
|
|
141
|
+
mercuryCallbacks[event](createData(requestId, 0, false, dataPath));
|
|
142
|
+
|
|
143
|
+
const result = await promise;
|
|
144
|
+
expect(result).to.deep.equal(["data0", "data1", "data2"]);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
describe("#lookupDetail", () => {
|
|
148
|
+
it("calls _request correctly", async () => {
|
|
149
|
+
webex.internal.device.orgId = "userOrgId";
|
|
150
|
+
webex.internal.dss._request = sinon
|
|
151
|
+
.stub()
|
|
152
|
+
.returns(Promise.resolve("some return value"));
|
|
153
|
+
|
|
154
|
+
const result = await webex.internal.dss.lookupDetail({ id: "test id" });
|
|
155
|
+
expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
|
|
156
|
+
{
|
|
157
|
+
dataPath: "lookupResult.entities",
|
|
158
|
+
resource: '/lookup/orgid/userOrgId/identity/test id/detail',
|
|
159
|
+
},
|
|
160
|
+
]);
|
|
161
|
+
expect(result).to.equal("some return value");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("works correctly", async () => {
|
|
165
|
+
await testRequest({
|
|
166
|
+
method: "lookupDetail",
|
|
167
|
+
dataPath: "lookupResult.entities",
|
|
168
|
+
event: "event:directory.lookup",
|
|
169
|
+
resource: '/lookup/orgid/userOrgId/identity/test id/detail',
|
|
170
|
+
params: {
|
|
171
|
+
id: "test id",
|
|
172
|
+
},
|
|
173
|
+
bodyParams: {},
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe("#lookup", () => {
|
|
179
|
+
it("calls _request correctly", async () => {
|
|
180
|
+
webex.internal.device.orgId = "userOrgId";
|
|
181
|
+
webex.internal.dss._request = sinon
|
|
182
|
+
.stub()
|
|
183
|
+
.returns(Promise.resolve("some return value"));
|
|
184
|
+
|
|
185
|
+
const result = await webex.internal.dss.lookup({ ids: ["id1", "id2"] });
|
|
186
|
+
expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
|
|
187
|
+
{
|
|
188
|
+
dataPath: "lookupResult.entities",
|
|
189
|
+
resource: '/lookup/orgid/userOrgId/identities',
|
|
190
|
+
params: {
|
|
191
|
+
lookupValues: ["id1", "id2"],
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
]);
|
|
195
|
+
expect(result).to.equal("some return value");
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("works correctly", async () => {
|
|
199
|
+
await testRequest({
|
|
200
|
+
method: "lookup",
|
|
201
|
+
dataPath: "lookupResult.entities",
|
|
202
|
+
event: "event:directory.lookup",
|
|
203
|
+
resource: '/lookup/orgid/userOrgId/identities',
|
|
204
|
+
params: {
|
|
205
|
+
ids: ["id1", "id2"],
|
|
206
|
+
},
|
|
207
|
+
bodyParams: {
|
|
208
|
+
lookupValues: ["id1", "id2"],
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe("#lookupByEmail", () => {
|
|
215
|
+
it("calls _request correctly", async () => {
|
|
216
|
+
webex.internal.device.orgId = "userOrgId";
|
|
217
|
+
webex.internal.dss._request = sinon
|
|
218
|
+
.stub()
|
|
219
|
+
.returns(Promise.resolve("some return value"));
|
|
220
|
+
|
|
221
|
+
const result = await webex.internal.dss.lookupByEmail({
|
|
222
|
+
emails: ["email1", "email2"],
|
|
223
|
+
});
|
|
224
|
+
expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
|
|
225
|
+
{
|
|
226
|
+
dataPath: "lookupResult.entities",
|
|
227
|
+
resource: '/lookup/orgid/userOrgId/emails',
|
|
228
|
+
params: {
|
|
229
|
+
lookupValues: ["email1", "email2"],
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
]);
|
|
233
|
+
expect(result).to.equal("some return value");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("works correctly", async () => {
|
|
237
|
+
await testRequest({
|
|
238
|
+
method: "lookupByEmail",
|
|
239
|
+
dataPath: "lookupResult.entities",
|
|
240
|
+
event: "event:directory.lookup",
|
|
241
|
+
resource: '/lookup/orgid/userOrgId/emails',
|
|
242
|
+
params: {
|
|
243
|
+
emails: ["email1", "email2"],
|
|
244
|
+
},
|
|
245
|
+
bodyParams: {
|
|
246
|
+
lookupValues: ["email1", "email2"],
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe("#search", () => {
|
|
253
|
+
it("calls _request correctly", async () => {
|
|
254
|
+
webex.internal.device.orgId = "userOrgId";
|
|
255
|
+
webex.internal.dss._request = sinon
|
|
256
|
+
.stub()
|
|
257
|
+
.returns(Promise.resolve("some return value"));
|
|
258
|
+
|
|
259
|
+
const result = await webex.internal.dss.search({
|
|
260
|
+
requestedTypes: ["PERSON", "ROBOT"],
|
|
261
|
+
resultSize: 100,
|
|
262
|
+
queryString: "query",
|
|
263
|
+
});
|
|
264
|
+
expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
|
|
265
|
+
{
|
|
266
|
+
dataPath: "directoryEntities",
|
|
267
|
+
resource: '/search/orgid/userOrgId/entities',
|
|
268
|
+
params: {
|
|
269
|
+
queryString: "query",
|
|
270
|
+
resultSize: 100,
|
|
271
|
+
requestedTypes: ["PERSON", "ROBOT"],
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
]);
|
|
275
|
+
expect(result).to.equal("some return value");
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("works correctly", async () => {
|
|
279
|
+
await testRequest({
|
|
280
|
+
method: "search",
|
|
281
|
+
event: "event:directory.search",
|
|
282
|
+
dataPath: "directoryEntities",
|
|
283
|
+
resource: '/search/orgid/userOrgId/entities',
|
|
284
|
+
params: {
|
|
285
|
+
requestedTypes: ["PERSON", "ROBOT"],
|
|
286
|
+
resultSize: 100,
|
|
287
|
+
queryString: "query",
|
|
288
|
+
},
|
|
289
|
+
bodyParams: {
|
|
290
|
+
requestedTypes: ["PERSON", "ROBOT"],
|
|
291
|
+
resultSize: 100,
|
|
292
|
+
queryString: "query",
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe("#_request", () => {
|
|
299
|
+
it("handles a request correctly", async () => {
|
|
300
|
+
webex.request = sinon.stub();
|
|
301
|
+
uuid.v4.returns("randomid");
|
|
302
|
+
const promise = webex.internal.dss._request({
|
|
303
|
+
resource: "/search/orgid/userOrgId/entities",
|
|
304
|
+
params: { some: "param" },
|
|
305
|
+
dataPath: "a.b.c",
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
expect(webex.request.getCall(0).args).to.deep.equal([
|
|
309
|
+
{
|
|
310
|
+
service: "directorySearch",
|
|
311
|
+
body: {
|
|
312
|
+
requestId: "randomid",
|
|
313
|
+
some: "param",
|
|
314
|
+
},
|
|
315
|
+
contentType: "application/json",
|
|
316
|
+
method: "POST",
|
|
317
|
+
resource: "/search/orgid/userOrgId/entities",
|
|
318
|
+
},
|
|
319
|
+
]);
|
|
320
|
+
|
|
321
|
+
webex.internal.dss.trigger(
|
|
322
|
+
webex.internal.dss._getResultEventName("randomid"),
|
|
323
|
+
{
|
|
324
|
+
sequence: 1,
|
|
325
|
+
a: {
|
|
326
|
+
b: {
|
|
327
|
+
c: ["data1"],
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
webex.internal.dss.trigger(
|
|
334
|
+
webex.internal.dss._getResultEventName("randomid"),
|
|
335
|
+
{
|
|
336
|
+
sequence: 2,
|
|
337
|
+
finished: true,
|
|
338
|
+
a: {
|
|
339
|
+
b: {
|
|
340
|
+
c: ["data2"],
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
webex.internal.dss.trigger(
|
|
347
|
+
webex.internal.dss._getResultEventName("randomid"),
|
|
348
|
+
{
|
|
349
|
+
sequence: 0,
|
|
350
|
+
a: {
|
|
351
|
+
b: {
|
|
352
|
+
c: ["data0"],
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
const result = await promise;
|
|
359
|
+
expect(result).to.deep.equal(["data0", "data1", "data2"]);
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|