@webex/internal-plugin-dss 2.60.1-next.9 → 2.60.2

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
@@ -2,13 +2,10 @@
2
2
  /*!
3
3
  * Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
4
4
  */
5
- /* eslint-disable no-underscore-dangle */
6
5
  import uuid from 'uuid';
7
6
  import {WebexPlugin} from '@webex/webex-core';
8
7
  import '@webex/internal-plugin-mercury';
9
8
  import {range, isEqual, get} from 'lodash';
10
-
11
- import {Timer} from '@webex/common-timers';
12
9
  import type {
13
10
  SearchOptions,
14
11
  LookupDetailOptions,
@@ -16,6 +13,7 @@ import type {
16
13
  LookupByEmailOptions,
17
14
  SearchPlaceOptions,
18
15
  } from './types';
16
+
19
17
  import {
20
18
  DSS_REGISTERED,
21
19
  DSS_UNREGISTERED,
@@ -24,15 +22,7 @@ import {
24
22
  DSS_SERVICE_NAME,
25
23
  DSS_SEARCH_MERCURY_EVENT,
26
24
  DSS_RESULT,
27
- LOOKUP_DATA_PATH,
28
- LOOKUP_FOUND_PATH,
29
- LOOKUP_NOT_FOUND_PATH,
30
- LOOKUP_REQUEST_KEY,
31
- SEARCH_DATA_PATH,
32
25
  } from './constants';
33
- import DssBatcher from './dss-batcher';
34
- import {DssTimeoutError} from './dss-errors';
35
- import {BatcherOptions, RequestOptions, RequestResult} from './types';
36
26
 
37
27
  const DSS = WebexPlugin.extend({
38
28
  namespace: 'DSS',
@@ -45,18 +35,6 @@ const DSS = WebexPlugin.extend({
45
35
  */
46
36
  registered: false,
47
37
 
48
- /**
49
- * Initializer
50
- * @private
51
- * @param {Object} attrs
52
- * @param {Object} options
53
- * @returns {undefined}
54
- */
55
- initialize(...args) {
56
- Reflect.apply(WebexPlugin.prototype.initialize, this, args);
57
- this.batchers = {};
58
- },
59
-
60
38
  /**
61
39
  * Explicitly sets up the DSS plugin by connecting to mercury, and listening for DSS events.
62
40
  * @returns {Promise}
@@ -136,7 +114,6 @@ const DSS = WebexPlugin.extend({
136
114
  },
137
115
 
138
116
  /**
139
- * constructs the event name based on request id
140
117
  * @param {UUID} requestId the id of the request
141
118
  * @returns {string}
142
119
  */
@@ -145,7 +122,6 @@ const DSS = WebexPlugin.extend({
145
122
  },
146
123
 
147
124
  /**
148
- * Takes incoming data and triggers correct events
149
125
  * @param {Object} data the event data
150
126
  * @returns {undefined}
151
127
  */
@@ -158,78 +134,40 @@ const DSS = WebexPlugin.extend({
158
134
  * Makes the request to the directory service
159
135
  * @param {Object} options
160
136
  * @param {string} options.resource the URL to query
161
- * @param {Mixed} options.params additional params for the body of the request
162
- * @param {string} options.dataPath the path to get the data in the result object
163
- * @param {string} [options.foundPath] the path to get the lookups of the found data
164
- * @param {string} [options.notFoundPath] the path to get the lookups of the not found data
165
- * @returns {Promise<Object>} result Resolves with an object
166
- * @returns {Array} result.resultArray an array of entities found
167
- * @returns {Array} result.foundArray an array of the lookups of the found entities (if foundPath provided)
168
- * @returns {Array} result.notFoundArray an array of the lookups of the not found entities (if notFoundPath provided)
169
- * @throws {DssTimeoutError} when server does not respond in the specified timeframe
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
170
140
  */
171
- _request(options: RequestOptions): Promise<RequestResult> {
172
- const {resource, params, dataPath, foundPath, notFoundPath} = options;
141
+ _request(options) {
142
+ const {resource, params, dataPath} = options;
173
143
 
174
- const timeout = this.config.requestTimeout;
175
144
  const requestId = uuid.v4();
176
145
  const eventName = this._getResultEventName(requestId);
177
146
  const result = {};
178
- let expectedSeqNums: string[];
179
- let notFoundArray: unknown[];
180
-
181
- return new Promise((resolve, reject) => {
182
- const timer = new Timer(() => {
183
- this.stopListening(this, eventName);
184
- reject(new DssTimeoutError({requestId, timeout, resource, params}));
185
- }, timeout);
147
+ let expectedSeqNums;
186
148
 
149
+ return new Promise((resolve) => {
187
150
  this.listenTo(this, eventName, (data) => {
188
- timer.reset();
189
- const resultData = get(data, dataPath, []);
190
- let found;
151
+ const resultData = get(data, dataPath);
191
152
 
192
- if (foundPath) {
193
- found = get(data, foundPath, []);
194
- }
195
- result[data.sequence] = foundPath ? {resultData, found} : {resultData};
153
+ result[data.sequence] = resultData;
196
154
 
197
155
  if (data.finished) {
198
156
  expectedSeqNums = range(data.sequence + 1).map(String);
199
- if (notFoundPath) {
200
- notFoundArray = get(data, notFoundPath, []);
201
- }
202
157
  }
203
158
 
204
159
  const done = isEqual(expectedSeqNums, Object.keys(result));
205
160
 
206
161
  if (done) {
207
- timer.cancel();
208
-
209
- const resultArray: any[] = [];
210
- const foundArray: any[] = [];
211
-
162
+ const resultArray = [];
212
163
  expectedSeqNums.forEach((index) => {
213
164
  const seqResult = result[index];
214
-
215
165
  if (seqResult) {
216
- resultArray.push(...seqResult.resultData);
217
- if (foundPath) {
218
- foundArray.push(...seqResult.found);
219
- }
166
+ resultArray.push(...seqResult);
220
167
  }
221
168
  });
222
- const resolveValue: RequestResult = {
223
- resultArray,
224
- };
225
-
226
- if (foundPath) {
227
- resolveValue.foundArray = foundArray;
228
- }
229
- if (notFoundPath) {
230
- resolveValue.notFoundArray = notFoundArray;
231
- }
232
- resolve(resolveValue);
169
+
170
+ resolve(resultArray);
233
171
  this.stopListening(this, eventName);
234
172
  }
235
173
  });
@@ -240,128 +178,62 @@ const DSS = WebexPlugin.extend({
240
178
  contentType: 'application/json',
241
179
  body: {requestId, ...params},
242
180
  });
243
- timer.start();
244
181
  });
245
182
  },
246
183
 
247
- /**
248
- * Uses a batcher to make the request to the directory service
249
- * @param {Object} options
250
- * @param {string} options.resource the URL to query
251
- * @param {string} options.value the id or email to lookup
252
- * @returns {Promise} Resolves with an array of entities found
253
- * @throws {DssTimeoutError} when server does not respond in the specified timeframe
254
- */
255
- _batchedLookup(options: BatcherOptions) {
256
- const {resource, lookupValue} = options;
257
- const dataPath = LOOKUP_DATA_PATH;
258
- const entitiesFoundPath = LOOKUP_FOUND_PATH;
259
- const entitiesNotFoundPath = LOOKUP_NOT_FOUND_PATH;
260
- const requestKey = LOOKUP_REQUEST_KEY;
261
-
262
- this.batchers[resource] =
263
- this.batchers[resource] ||
264
- new DssBatcher({
265
- resource,
266
- dataPath,
267
- entitiesFoundPath,
268
- entitiesNotFoundPath,
269
- requestKey,
270
- parent: this,
271
- });
272
-
273
- return this.batchers[resource].request(lookupValue);
274
- },
275
-
276
184
  /**
277
185
  * Retrieves detailed information about an entity
278
186
  * @param {Object} options
279
187
  * @param {UUID} options.id the id of the entity to lookup
280
- * @returns {Promise} Resolves with the entity found or null if not found
281
- * @throws {DssTimeoutError} when server does not respond in the specified timeframe
188
+ * @returns {Promise} Resolves with an array of entities found
282
189
  */
283
190
  lookupDetail(options: LookupDetailOptions) {
284
191
  const {id} = options;
285
192
 
286
- const resource = `/lookup/orgid/${this.webex.internal.device.orgId}/identity/${id}/detail`;
287
-
288
193
  return this._request({
289
- dataPath: LOOKUP_DATA_PATH,
290
- foundPath: LOOKUP_FOUND_PATH,
291
- resource,
292
- }).then(({resultArray, foundArray}) => {
293
- // TODO: find out what is actually returned!
294
- if (foundArray[0] === id) {
295
- return resultArray[0];
296
- }
297
-
298
- return null;
194
+ dataPath: 'lookupResult.entities',
195
+ resource: `/lookup/orgid/${this.webex.internal.device.orgId}/identity/${id}/detail`,
299
196
  });
300
197
  },
301
198
 
302
199
  /**
303
- * Retrieves basic information about an entity within an organization
200
+ * Retrieves basic information about a list entities within an organization
304
201
  * @param {Object} options
305
- * @param {UUID} options.id the id of the entity to lookup
306
- * @param {UUID} [options.entityProviderType] the provider to query
307
- * @param {Boolean} options.shouldBatch whether to batch the query, set to false for single immediate result (defaults to true)
308
- * @returns {Promise} Resolves with the entity found or null if not found
309
- * @throws {DssTimeoutError} when server does not respond in the specified timeframe
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
310
205
  */
311
206
  lookup(options: LookupOptions) {
312
- const {id, entityProviderType, shouldBatch = true} = options;
207
+ const {ids, entityProviderType} = options;
313
208
 
314
209
  const resource = entityProviderType
315
210
  ? `/lookup/orgid/${this.webex.internal.device.orgId}/entityprovidertype/${entityProviderType}`
316
211
  : `/lookup/orgid/${this.webex.internal.device.orgId}/identities`;
317
212
 
318
- if (shouldBatch) {
319
- return this._batchedLookup({
320
- resource,
321
- lookupValue: id,
322
- });
323
- }
324
-
325
213
  return this._request({
326
- dataPath: LOOKUP_DATA_PATH,
327
- foundPath: LOOKUP_FOUND_PATH,
214
+ dataPath: 'lookupResult.entities',
328
215
  resource,
329
216
  params: {
330
- [LOOKUP_REQUEST_KEY]: [id],
217
+ lookupValues: ids,
331
218
  },
332
- }).then(({resultArray, foundArray}) => {
333
- if (foundArray[0] === id) {
334
- return resultArray[0];
335
- }
336
-
337
- return null;
338
219
  });
339
220
  },
340
221
 
341
222
  /**
342
- * Retrieves basic information about an enitity within an organization
223
+ * Retrieves basic information about a list entities within an organization
343
224
  * @param {Object} options
344
- * @param {UUID} options.email the email of the entity to lookup
345
- * @returns {Promise} Resolves with the entity found or rejects if not found
346
- * @throws {DssTimeoutError} when server does not respond in the specified timeframe
225
+ * @param {UUID} options.emails the emails of the entities to lookup
226
+ * @returns {Promise} Resolves with an array of entities found
347
227
  */
348
228
  lookupByEmail(options: LookupByEmailOptions) {
349
- const {email} = options;
350
- const resource = `/lookup/orgid/${this.webex.internal.device.orgId}/emails`;
229
+ const {emails} = options;
351
230
 
352
231
  return this._request({
353
- dataPath: LOOKUP_DATA_PATH,
354
- foundPath: LOOKUP_FOUND_PATH,
355
- resource,
232
+ dataPath: 'lookupResult.entities',
233
+ resource: `/lookup/orgid/${this.webex.internal.device.orgId}/emails`,
356
234
  params: {
357
- [LOOKUP_REQUEST_KEY]: [email],
235
+ lookupValues: emails,
358
236
  },
359
- }).then(({resultArray, foundArray}) => {
360
- if (foundArray[0] === email) {
361
- return resultArray[0];
362
- }
363
-
364
- return null;
365
237
  });
366
238
  },
367
239
 
@@ -372,20 +244,19 @@ const DSS = WebexPlugin.extend({
372
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
373
245
  * @param {number} options.resultSize The maximum number of results returned from each provider
374
246
  * @returns {Promise} Resolves with an array of entities found
375
- * @throws {DssTimeoutError} when server does not respond in the specified timeframe
376
247
  */
377
248
  search(options: SearchOptions) {
378
249
  const {requestedTypes, resultSize, queryString} = options;
379
250
 
380
251
  return this._request({
381
- dataPath: SEARCH_DATA_PATH,
252
+ dataPath: 'directoryEntities',
382
253
  resource: `/search/orgid/${this.webex.internal.device.orgId}/entities`,
383
254
  params: {
384
255
  queryString,
385
256
  resultSize,
386
257
  requestedTypes,
387
258
  },
388
- }).then(({resultArray}) => resultArray);
259
+ });
389
260
  },
390
261
 
391
262
  /**
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import {registerInternalPlugin} from '@webex/webex-core';
2
2
 
3
3
  import DSS from './dss';
4
- import config from './config';
5
4
 
6
- registerInternalPlugin('dss', DSS, {config});
5
+ registerInternalPlugin('dss', DSS);
7
6
 
8
7
  export {default} from './dss';
package/src/types.ts CHANGED
@@ -1,17 +1,3 @@
1
- export interface RequestOptions {
2
- resource: string;
3
- dataPath: string;
4
- foundPath?: string;
5
- notFoundPath?: string;
6
- params?: Record<string, unknown>;
7
- }
8
-
9
- export interface RequestResult {
10
- foundArray?: any[];
11
- notFoundArray?: any[];
12
- resultArray: any[];
13
- }
14
-
15
1
  export interface LookupDetailOptions {
16
2
  id: string;
17
3
  }
@@ -24,16 +10,14 @@ export enum EntityProviderType {
24
10
  }
25
11
 
26
12
  export interface LookupOptions {
27
- id: string;
13
+ ids: string[];
28
14
  entityProviderType?: EntityProviderType;
29
- shouldBatch?: boolean;
30
15
  }
31
16
 
32
17
  export interface LookupByEmailOptions {
33
- email: string;
18
+ emails: string[];
34
19
  }
35
20
 
36
- // eslint-disable-next-line no-shadow
37
21
  export enum SearchType {
38
22
  PERSON = 'PERSON',
39
23
  CALLING_SERVICE = 'CALLING_SERVICE',
@@ -48,11 +32,6 @@ export interface SearchOptions {
48
32
  queryString: string;
49
33
  }
50
34
 
51
- export interface BatcherOptions {
52
- resource: string;
53
- lookupValue: string;
54
- }
55
-
56
35
  export interface SearchPlaceOptions {
57
36
  resultSize: number;
58
37
  queryString: string;