@webex/internal-plugin-dss 2.59.2 → 2.59.3-next.1

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/src/dss.ts CHANGED
@@ -1,288 +1,288 @@
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 {
10
- SearchOptions,
11
- LookupDetailOptions,
12
- LookupOptions,
13
- LookupByEmailOptions,
14
- SearchPlaceOptions,
15
- } from './types';
16
-
17
- import {
18
- DSS_REGISTERED,
19
- DSS_UNREGISTERED,
20
- DSS_LOOKUP_MERCURY_EVENT,
21
- DSS_LOOKUP_RESULT,
22
- DSS_SERVICE_NAME,
23
- DSS_SEARCH_MERCURY_EVENT,
24
- DSS_RESULT,
25
- } from './constants';
26
-
27
- const DSS = WebexPlugin.extend({
28
- namespace: 'DSS',
29
-
30
- /**
31
- * registered value indicating events registration is successful
32
- * @instance
33
- * @type {Boolean}
34
- * @memberof DSS
35
- */
36
- registered: false,
37
-
38
- /**
39
- * Explicitly sets up the DSS plugin by connecting to mercury, and listening for DSS events.
40
- * @returns {Promise}
41
- * @public
42
- * @memberof DSS
43
- */
44
- register() {
45
- if (!this.webex.canAuthorize) {
46
- this.logger.error('DSS->register#ERROR, Unable to register, SDK cannot authorize');
47
-
48
- return Promise.reject(new Error('SDK cannot authorize'));
49
- }
50
-
51
- if (this.registered) {
52
- this.logger.info('dss->register#INFO, DSS plugin already registered');
53
-
54
- return Promise.resolve();
55
- }
56
-
57
- return this.webex.internal.mercury
58
- .connect()
59
- .then(() => {
60
- this.listenForEvents();
61
- this.trigger(DSS_REGISTERED);
62
- this.registered = true;
63
- })
64
- .catch((error) => {
65
- this.logger.error(`DSS->register#ERROR, Unable to register, ${error.message}`);
66
-
67
- return Promise.reject(error);
68
- });
69
- },
70
-
71
- /**
72
- * Explicitly tears down the DSS plugin by disconnecting from mercury, and stops listening to DSS events
73
- * @returns {Promise}
74
- * @public
75
- * @memberof DSS
76
- */
77
- unregister() {
78
- if (!this.registered) {
79
- this.logger.info('DSS->unregister#INFO, DSS plugin already unregistered');
80
-
81
- return Promise.resolve();
82
- }
83
-
84
- this.stopListeningForEvents();
85
-
86
- return this.webex.internal.mercury.disconnect().then(() => {
87
- this.trigger(DSS_UNREGISTERED);
88
- this.registered = false;
89
- });
90
- },
91
-
92
- /**
93
- * registers for DSS events through mercury
94
- * @returns {undefined}
95
- * @private
96
- */
97
- listenForEvents() {
98
- this.webex.internal.mercury.on(DSS_LOOKUP_MERCURY_EVENT, (envelope) => {
99
- this._handleEvent(envelope.data);
100
- });
101
- this.webex.internal.mercury.on(DSS_SEARCH_MERCURY_EVENT, (envelope) => {
102
- this._handleEvent(envelope.data);
103
- });
104
- },
105
-
106
- /**
107
- * unregisteres all the DSS events from mercury
108
- * @returns {undefined}
109
- * @private
110
- */
111
- stopListeningForEvents() {
112
- this.webex.internal.mercury.off(DSS_LOOKUP_MERCURY_EVENT);
113
- this.webex.internal.mercury.off(DSS_SEARCH_MERCURY_EVENT);
114
- },
115
-
116
- /**
117
- * @param {UUID} requestId the id of the request
118
- * @returns {string}
119
- */
120
- _getResultEventName(requestId) {
121
- return `${DSS_RESULT}${requestId}`;
122
- },
123
-
124
- /**
125
- * @param {Object} data the event data
126
- * @returns {undefined}
127
- */
128
- _handleEvent(data) {
129
- this.trigger(this._getResultEventName(data.requestId), data);
130
- this.trigger(DSS_LOOKUP_RESULT, data);
131
- },
132
-
133
- /**
134
- * Makes the request to the directory service
135
- * @param {Object} options
136
- * @param {string} options.resource the URL to query
137
- * @param {string} options.params additional params for the body of the request
138
- * @param {string} options.dataPath to path to get the data in the result object
139
- * @returns {Promise} Resolves with an array of entities found
140
- */
141
- _request(options) {
142
- const {resource, params, dataPath} = options;
143
-
144
- const requestId = uuid.v4();
145
- const eventName = this._getResultEventName(requestId);
146
- const result = {};
147
- let expectedSeqNums;
148
-
149
- return new Promise((resolve) => {
150
- this.listenTo(this, eventName, (data) => {
151
- const resultData = get(data, dataPath);
152
-
153
- result[data.sequence] = resultData;
154
-
155
- if (data.finished) {
156
- expectedSeqNums = range(data.sequence + 1).map(String);
157
- }
158
-
159
- const done = isEqual(expectedSeqNums, Object.keys(result));
160
-
161
- if (done) {
162
- const resultArray = [];
163
- expectedSeqNums.forEach((index) => {
164
- const seqResult = result[index];
165
- if (seqResult) {
166
- resultArray.push(...seqResult);
167
- }
168
- });
169
-
170
- resolve(resultArray);
171
- this.stopListening(this, eventName);
172
- }
173
- });
174
- this.webex.request({
175
- service: DSS_SERVICE_NAME,
176
- resource,
177
- method: 'POST',
178
- contentType: 'application/json',
179
- body: {requestId, ...params},
180
- });
181
- });
182
- },
183
-
184
- /**
185
- * Retrieves detailed information about an entity
186
- * @param {Object} options
187
- * @param {UUID} options.id the id of the entity to lookup
188
- * @returns {Promise} Resolves with an array of entities found
189
- */
190
- lookupDetail(options: LookupDetailOptions) {
191
- const {id} = options;
192
-
193
- return this._request({
194
- dataPath: 'lookupResult.entities',
195
- resource: `/lookup/orgid/${this.webex.internal.device.orgId}/identity/${id}/detail`,
196
- });
197
- },
198
-
199
- /**
200
- * Retrieves basic information about a list entities within an organization
201
- * @param {Object} options
202
- * @param {UUID} options.ids the id of the entity to lookup
203
- * @param {UUID} options.entityProviderType the provider to query (optional)
204
- * @returns {Promise} Resolves with an array of entities found
205
- */
206
- lookup(options: LookupOptions) {
207
- const {ids, entityProviderType} = options;
208
-
209
- const resource = entityProviderType
210
- ? `/lookup/orgid/${this.webex.internal.device.orgId}/entityprovidertype/${entityProviderType}`
211
- : `/lookup/orgid/${this.webex.internal.device.orgId}/identities`;
212
-
213
- return this._request({
214
- dataPath: 'lookupResult.entities',
215
- resource,
216
- params: {
217
- lookupValues: ids,
218
- },
219
- });
220
- },
221
-
222
- /**
223
- * Retrieves basic information about a list entities within an organization
224
- * @param {Object} options
225
- * @param {UUID} options.emails the emails of the entities to lookup
226
- * @returns {Promise} Resolves with an array of entities found
227
- */
228
- lookupByEmail(options: LookupByEmailOptions) {
229
- const {emails} = options;
230
-
231
- return this._request({
232
- dataPath: 'lookupResult.entities',
233
- resource: `/lookup/orgid/${this.webex.internal.device.orgId}/emails`,
234
- params: {
235
- lookupValues: emails,
236
- },
237
- });
238
- },
239
-
240
- /**
241
- * Search for information about entities
242
- * @param {Object} options
243
- * @param {SearchType[]} options.requestedTypes an array of search types from: PERSON, CALLING_SERVICE, EXTERNAL_CALLING, ROOM, ROBOT
244
- * @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
245
- * @param {number} options.resultSize The maximum number of results returned from each provider
246
- * @returns {Promise} Resolves with an array of entities found
247
- */
248
- search(options: SearchOptions) {
249
- const {requestedTypes, resultSize, queryString} = options;
250
-
251
- return this._request({
252
- dataPath: 'directoryEntities',
253
- resource: `/search/orgid/${this.webex.internal.device.orgId}/entities`,
254
- params: {
255
- queryString,
256
- resultSize,
257
- requestedTypes,
258
- },
259
- });
260
- },
261
-
262
- /**
263
- * Search for information about places
264
- * @param {Object} options
265
- * @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: placeName, displayName.
266
- * @param {number} options.resultSize The maximum number of results returned from each provider
267
- * @returns {Promise} Resolves with an array of entities found
268
- */
269
- searchPlaces(options: SearchPlaceOptions) {
270
- const {resultSize, queryString, isOnlySchedulableRooms} = options;
271
-
272
- return this._request({
273
- dataPath: 'directoryEntities',
274
- resource: `/search/orgid/${this.webex.internal.device.orgId}/places`,
275
- params: {
276
- queryString,
277
- resultSize,
278
- isOnlySchedulableRooms,
279
- },
280
- }).catch((error) => {
281
- this.logger.error(`DSS->search place#ERROR, search place failure, ${error.message}`);
282
-
283
- return Promise.reject(error);
284
- });
285
- },
286
- });
287
-
288
- export default DSS;
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 {
10
+ SearchOptions,
11
+ LookupDetailOptions,
12
+ LookupOptions,
13
+ LookupByEmailOptions,
14
+ SearchPlaceOptions,
15
+ } from './types';
16
+
17
+ import {
18
+ DSS_REGISTERED,
19
+ DSS_UNREGISTERED,
20
+ DSS_LOOKUP_MERCURY_EVENT,
21
+ DSS_LOOKUP_RESULT,
22
+ DSS_SERVICE_NAME,
23
+ DSS_SEARCH_MERCURY_EVENT,
24
+ DSS_RESULT,
25
+ } from './constants';
26
+
27
+ const DSS = WebexPlugin.extend({
28
+ namespace: 'DSS',
29
+
30
+ /**
31
+ * registered value indicating events registration is successful
32
+ * @instance
33
+ * @type {Boolean}
34
+ * @memberof DSS
35
+ */
36
+ registered: false,
37
+
38
+ /**
39
+ * Explicitly sets up the DSS plugin by connecting to mercury, and listening for DSS events.
40
+ * @returns {Promise}
41
+ * @public
42
+ * @memberof DSS
43
+ */
44
+ register() {
45
+ if (!this.webex.canAuthorize) {
46
+ this.logger.error('DSS->register#ERROR, Unable to register, SDK cannot authorize');
47
+
48
+ return Promise.reject(new Error('SDK cannot authorize'));
49
+ }
50
+
51
+ if (this.registered) {
52
+ this.logger.info('dss->register#INFO, DSS plugin already registered');
53
+
54
+ return Promise.resolve();
55
+ }
56
+
57
+ return this.webex.internal.mercury
58
+ .connect()
59
+ .then(() => {
60
+ this.listenForEvents();
61
+ this.trigger(DSS_REGISTERED);
62
+ this.registered = true;
63
+ })
64
+ .catch((error) => {
65
+ this.logger.error(`DSS->register#ERROR, Unable to register, ${error.message}`);
66
+
67
+ return Promise.reject(error);
68
+ });
69
+ },
70
+
71
+ /**
72
+ * Explicitly tears down the DSS plugin by disconnecting from mercury, and stops listening to DSS events
73
+ * @returns {Promise}
74
+ * @public
75
+ * @memberof DSS
76
+ */
77
+ unregister() {
78
+ if (!this.registered) {
79
+ this.logger.info('DSS->unregister#INFO, DSS plugin already unregistered');
80
+
81
+ return Promise.resolve();
82
+ }
83
+
84
+ this.stopListeningForEvents();
85
+
86
+ return this.webex.internal.mercury.disconnect().then(() => {
87
+ this.trigger(DSS_UNREGISTERED);
88
+ this.registered = false;
89
+ });
90
+ },
91
+
92
+ /**
93
+ * registers for DSS events through mercury
94
+ * @returns {undefined}
95
+ * @private
96
+ */
97
+ listenForEvents() {
98
+ this.webex.internal.mercury.on(DSS_LOOKUP_MERCURY_EVENT, (envelope) => {
99
+ this._handleEvent(envelope.data);
100
+ });
101
+ this.webex.internal.mercury.on(DSS_SEARCH_MERCURY_EVENT, (envelope) => {
102
+ this._handleEvent(envelope.data);
103
+ });
104
+ },
105
+
106
+ /**
107
+ * unregisteres all the DSS events from mercury
108
+ * @returns {undefined}
109
+ * @private
110
+ */
111
+ stopListeningForEvents() {
112
+ this.webex.internal.mercury.off(DSS_LOOKUP_MERCURY_EVENT);
113
+ this.webex.internal.mercury.off(DSS_SEARCH_MERCURY_EVENT);
114
+ },
115
+
116
+ /**
117
+ * @param {UUID} requestId the id of the request
118
+ * @returns {string}
119
+ */
120
+ _getResultEventName(requestId) {
121
+ return `${DSS_RESULT}${requestId}`;
122
+ },
123
+
124
+ /**
125
+ * @param {Object} data the event data
126
+ * @returns {undefined}
127
+ */
128
+ _handleEvent(data) {
129
+ this.trigger(this._getResultEventName(data.requestId), data);
130
+ this.trigger(DSS_LOOKUP_RESULT, data);
131
+ },
132
+
133
+ /**
134
+ * Makes the request to the directory service
135
+ * @param {Object} options
136
+ * @param {string} options.resource the URL to query
137
+ * @param {string} options.params additional params for the body of the request
138
+ * @param {string} options.dataPath to path to get the data in the result object
139
+ * @returns {Promise} Resolves with an array of entities found
140
+ */
141
+ _request(options) {
142
+ const {resource, params, dataPath} = options;
143
+
144
+ const requestId = uuid.v4();
145
+ const eventName = this._getResultEventName(requestId);
146
+ const result = {};
147
+ let expectedSeqNums;
148
+
149
+ return new Promise((resolve) => {
150
+ this.listenTo(this, eventName, (data) => {
151
+ const resultData = get(data, dataPath);
152
+
153
+ result[data.sequence] = resultData;
154
+
155
+ if (data.finished) {
156
+ expectedSeqNums = range(data.sequence + 1).map(String);
157
+ }
158
+
159
+ const done = isEqual(expectedSeqNums, Object.keys(result));
160
+
161
+ if (done) {
162
+ const resultArray = [];
163
+ expectedSeqNums.forEach((index) => {
164
+ const seqResult = result[index];
165
+ if (seqResult) {
166
+ resultArray.push(...seqResult);
167
+ }
168
+ });
169
+
170
+ resolve(resultArray);
171
+ this.stopListening(this, eventName);
172
+ }
173
+ });
174
+ this.webex.request({
175
+ service: DSS_SERVICE_NAME,
176
+ resource,
177
+ method: 'POST',
178
+ contentType: 'application/json',
179
+ body: {requestId, ...params},
180
+ });
181
+ });
182
+ },
183
+
184
+ /**
185
+ * Retrieves detailed information about an entity
186
+ * @param {Object} options
187
+ * @param {UUID} options.id the id of the entity to lookup
188
+ * @returns {Promise} Resolves with an array of entities found
189
+ */
190
+ lookupDetail(options: LookupDetailOptions) {
191
+ const {id} = options;
192
+
193
+ return this._request({
194
+ dataPath: 'lookupResult.entities',
195
+ resource: `/lookup/orgid/${this.webex.internal.device.orgId}/identity/${id}/detail`,
196
+ });
197
+ },
198
+
199
+ /**
200
+ * Retrieves basic information about a list entities within an organization
201
+ * @param {Object} options
202
+ * @param {UUID} options.ids the id of the entity to lookup
203
+ * @param {UUID} options.entityProviderType the provider to query (optional)
204
+ * @returns {Promise} Resolves with an array of entities found
205
+ */
206
+ lookup(options: LookupOptions) {
207
+ const {ids, entityProviderType} = options;
208
+
209
+ const resource = entityProviderType
210
+ ? `/lookup/orgid/${this.webex.internal.device.orgId}/entityprovidertype/${entityProviderType}`
211
+ : `/lookup/orgid/${this.webex.internal.device.orgId}/identities`;
212
+
213
+ return this._request({
214
+ dataPath: 'lookupResult.entities',
215
+ resource,
216
+ params: {
217
+ lookupValues: ids,
218
+ },
219
+ });
220
+ },
221
+
222
+ /**
223
+ * Retrieves basic information about a list entities within an organization
224
+ * @param {Object} options
225
+ * @param {UUID} options.emails the emails of the entities to lookup
226
+ * @returns {Promise} Resolves with an array of entities found
227
+ */
228
+ lookupByEmail(options: LookupByEmailOptions) {
229
+ const {emails} = options;
230
+
231
+ return this._request({
232
+ dataPath: 'lookupResult.entities',
233
+ resource: `/lookup/orgid/${this.webex.internal.device.orgId}/emails`,
234
+ params: {
235
+ lookupValues: emails,
236
+ },
237
+ });
238
+ },
239
+
240
+ /**
241
+ * Search for information about entities
242
+ * @param {Object} options
243
+ * @param {SearchType[]} options.requestedTypes an array of search types from: PERSON, CALLING_SERVICE, EXTERNAL_CALLING, ROOM, ROBOT
244
+ * @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
245
+ * @param {number} options.resultSize The maximum number of results returned from each provider
246
+ * @returns {Promise} Resolves with an array of entities found
247
+ */
248
+ search(options: SearchOptions) {
249
+ const {requestedTypes, resultSize, queryString} = options;
250
+
251
+ return this._request({
252
+ dataPath: 'directoryEntities',
253
+ resource: `/search/orgid/${this.webex.internal.device.orgId}/entities`,
254
+ params: {
255
+ queryString,
256
+ resultSize,
257
+ requestedTypes,
258
+ },
259
+ });
260
+ },
261
+
262
+ /**
263
+ * Search for information about places
264
+ * @param {Object} options
265
+ * @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: placeName, displayName.
266
+ * @param {number} options.resultSize The maximum number of results returned from each provider
267
+ * @returns {Promise} Resolves with an array of entities found
268
+ */
269
+ searchPlaces(options: SearchPlaceOptions) {
270
+ const {resultSize, queryString, isOnlySchedulableRooms} = options;
271
+
272
+ return this._request({
273
+ dataPath: 'directoryEntities',
274
+ resource: `/search/orgid/${this.webex.internal.device.orgId}/places`,
275
+ params: {
276
+ queryString,
277
+ resultSize,
278
+ isOnlySchedulableRooms,
279
+ },
280
+ }).catch((error) => {
281
+ this.logger.error(`DSS->search place#ERROR, search place failure, ${error.message}`);
282
+
283
+ return Promise.reject(error);
284
+ });
285
+ },
286
+ });
287
+
288
+ export default DSS;
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- import {registerInternalPlugin} from '@webex/webex-core';
2
-
3
- import DSS from './dss';
4
-
5
- registerInternalPlugin('dss', DSS);
6
-
7
- export {default} from './dss';
1
+ import {registerInternalPlugin} from '@webex/webex-core';
2
+
3
+ import DSS from './dss';
4
+
5
+ registerInternalPlugin('dss', DSS);
6
+
7
+ export {default} from './dss';
package/src/types.ts CHANGED
@@ -1,39 +1,39 @@
1
- export interface LookupDetailOptions {
2
- id: string;
3
- }
4
-
5
- export enum EntityProviderType {
6
- CI_USER = 'CI_USER',
7
- CI_MACHINE = 'CI_MACHINE',
8
- CONTACTS = 'CONTACTS',
9
- CSDM = 'CSDM',
10
- }
11
-
12
- export interface LookupOptions {
13
- ids: string[];
14
- entityProviderType?: EntityProviderType;
15
- }
16
-
17
- export interface LookupByEmailOptions {
18
- emails: string[];
19
- }
20
-
21
- export enum SearchType {
22
- PERSON = 'PERSON',
23
- CALLING_SERVICE = 'CALLING_SERVICE',
24
- EXTERNAL_CALLING = 'EXTERNAL_CALLING',
25
- ROOM = 'ROOM',
26
- ROBOT = 'ROBOT',
27
- }
28
-
29
- export interface SearchOptions {
30
- requestedTypes: SearchType[];
31
- resultSize: number;
32
- queryString: string;
33
- }
34
-
35
- export interface SearchPlaceOptions {
36
- resultSize: number;
37
- queryString: string;
38
- isOnlySchedulableRooms: boolean;
39
- }
1
+ export interface LookupDetailOptions {
2
+ id: string;
3
+ }
4
+
5
+ export enum EntityProviderType {
6
+ CI_USER = 'CI_USER',
7
+ CI_MACHINE = 'CI_MACHINE',
8
+ CONTACTS = 'CONTACTS',
9
+ CSDM = 'CSDM',
10
+ }
11
+
12
+ export interface LookupOptions {
13
+ ids: string[];
14
+ entityProviderType?: EntityProviderType;
15
+ }
16
+
17
+ export interface LookupByEmailOptions {
18
+ emails: string[];
19
+ }
20
+
21
+ export enum SearchType {
22
+ PERSON = 'PERSON',
23
+ CALLING_SERVICE = 'CALLING_SERVICE',
24
+ EXTERNAL_CALLING = 'EXTERNAL_CALLING',
25
+ ROOM = 'ROOM',
26
+ ROBOT = 'ROBOT',
27
+ }
28
+
29
+ export interface SearchOptions {
30
+ requestedTypes: SearchType[];
31
+ resultSize: number;
32
+ queryString: string;
33
+ }
34
+
35
+ export interface SearchPlaceOptions {
36
+ resultSize: number;
37
+ queryString: string;
38
+ isOnlySchedulableRooms: boolean;
39
+ }