@webex/internal-plugin-dss 3.0.0-beta.4 → 3.0.0-beta.400
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/config.js +36 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.js +11 -3
- package/dist/constants.js.map +1 -1
- package/dist/dss-batcher.js +139 -0
- package/dist/dss-batcher.js.map +1 -0
- package/dist/dss-errors.js +50 -0
- package/dist/dss-errors.js.map +1 -0
- package/dist/dss.js +194 -93
- package/dist/dss.js.map +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/types.js +1 -5
- package/dist/types.js.map +1 -1
- package/package.json +9 -6
- package/src/config.ts +31 -0
- package/src/constants.ts +5 -0
- package/src/dss-batcher.ts +129 -0
- package/src/dss-errors.ts +36 -0
- package/src/dss.ts +211 -52
- package/src/index.ts +2 -1
- package/src/types.ts +36 -9
- package/test/unit/spec/dss-batcher.ts +139 -0
- package/test/unit/spec/dss.ts +1082 -172
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/internal-plugin-dss",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.400",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Colin Read <coread@cisco.com>",
|
|
@@ -21,14 +21,17 @@
|
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@webex/
|
|
25
|
-
"@webex/
|
|
24
|
+
"@webex/common": "3.0.0-beta.400",
|
|
25
|
+
"@webex/common-timers": "3.0.0-beta.400",
|
|
26
|
+
"@webex/internal-plugin-mercury": "3.0.0-beta.400",
|
|
27
|
+
"@webex/webex-core": "3.0.0-beta.400",
|
|
26
28
|
"lodash": "^4.17.21",
|
|
27
29
|
"uuid": "^3.3.2"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
30
|
-
"@webex/internal-plugin-dss": "3.0.0-beta.
|
|
31
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
32
|
-
"@webex/test-helper-mock-webex": "3.0.0-beta.
|
|
32
|
+
"@webex/internal-plugin-dss": "3.0.0-beta.400",
|
|
33
|
+
"@webex/test-helper-chai": "3.0.0-beta.400",
|
|
34
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.400",
|
|
35
|
+
"sinon": "^9.2.4"
|
|
33
36
|
}
|
|
34
37
|
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
dss: {
|
|
7
|
+
/**
|
|
8
|
+
* Timeout before DSS request fails, in milliseconds.
|
|
9
|
+
* @type {Number}
|
|
10
|
+
*/
|
|
11
|
+
requestTimeout: 6000,
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Debounce wait (ms) before sending a dss request (gap between lookups that will trigger a request)
|
|
15
|
+
* @type {Number}
|
|
16
|
+
*/
|
|
17
|
+
batcherWait: 50,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Maximum queue size before sending a dss request
|
|
21
|
+
* @type {Number}
|
|
22
|
+
*/
|
|
23
|
+
batcherMaxCalls: 50,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Debounce max wait (ms) before sending a dss request (time from first lookup that will trigger a request)
|
|
27
|
+
* @type {Number}
|
|
28
|
+
*/
|
|
29
|
+
batcherMaxWait: 150,
|
|
30
|
+
},
|
|
31
|
+
};
|
package/src/constants.ts
CHANGED
|
@@ -12,3 +12,8 @@ export const SEARCH_TYPES = {
|
|
|
12
12
|
ROOM: 'ROOM',
|
|
13
13
|
ROBOT: 'ROBOT',
|
|
14
14
|
};
|
|
15
|
+
export const LOOKUP_DATA_PATH = 'lookupResult.entities';
|
|
16
|
+
export const LOOKUP_FOUND_PATH = 'lookupResult.entitiesFound';
|
|
17
|
+
export const LOOKUP_NOT_FOUND_PATH = 'lookupResult.entitiesNotFound';
|
|
18
|
+
export const LOOKUP_REQUEST_KEY = 'lookupValues';
|
|
19
|
+
export const SEARCH_DATA_PATH = 'directoryEntities';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
/* eslint-disable no-underscore-dangle */
|
|
5
|
+
|
|
6
|
+
import {Batcher} from '@webex/webex-core';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @class
|
|
10
|
+
*/
|
|
11
|
+
const DssBatcher = Batcher.extend({
|
|
12
|
+
namespace: 'DSS',
|
|
13
|
+
|
|
14
|
+
props: {
|
|
15
|
+
resource: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
required: true,
|
|
18
|
+
setOnce: true,
|
|
19
|
+
allowNull: false,
|
|
20
|
+
},
|
|
21
|
+
dataPath: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
required: true,
|
|
24
|
+
setOnce: true,
|
|
25
|
+
allowNull: false,
|
|
26
|
+
},
|
|
27
|
+
entitiesFoundPath: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
required: true,
|
|
30
|
+
setOnce: true,
|
|
31
|
+
allowNull: false,
|
|
32
|
+
},
|
|
33
|
+
entitiesNotFoundPath: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
required: true,
|
|
36
|
+
setOnce: true,
|
|
37
|
+
allowNull: false,
|
|
38
|
+
},
|
|
39
|
+
requestKey: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
required: true,
|
|
42
|
+
setOnce: true,
|
|
43
|
+
allowNull: false,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Submits the DSS request
|
|
49
|
+
* @param {Object} payload
|
|
50
|
+
* @returns {Promise<Array>}
|
|
51
|
+
*/
|
|
52
|
+
submitHttpRequest(payload: unknown) {
|
|
53
|
+
return this.parent._request({
|
|
54
|
+
dataPath: this.dataPath,
|
|
55
|
+
foundPath: this.entitiesFoundPath,
|
|
56
|
+
notFoundPath: this.entitiesNotFoundPath,
|
|
57
|
+
resource: this.resource,
|
|
58
|
+
params: {
|
|
59
|
+
lookupValues: payload,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Actions taken when the http request returns a success
|
|
66
|
+
* @param {Promise<Array>} res
|
|
67
|
+
* @returns {Promise<undefined>}
|
|
68
|
+
*/
|
|
69
|
+
handleHttpSuccess(res) {
|
|
70
|
+
const successItems = res.foundArray.map((requestValue, index) => ({
|
|
71
|
+
requestValue,
|
|
72
|
+
entity: res.resultArray[index],
|
|
73
|
+
}));
|
|
74
|
+
const failureItems = res.notFoundArray.map((requestValue) => ({requestValue, entity: null}));
|
|
75
|
+
|
|
76
|
+
return Promise.all(successItems.concat(failureItems).map((item) => this.acceptItem(item)));
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checks if the item was found
|
|
81
|
+
* @param {Object} item
|
|
82
|
+
* @returns {Promise<Boolean>}
|
|
83
|
+
*/
|
|
84
|
+
didItemFail(item) {
|
|
85
|
+
return Promise.resolve(item.entity === null);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Finds the Defer for the specified item and resolves its promise with null
|
|
90
|
+
* @param {Object} item
|
|
91
|
+
* @returns {Promise<undefined>}
|
|
92
|
+
*/
|
|
93
|
+
handleItemFailure(item) {
|
|
94
|
+
return this.getDeferredForResponse(item).then((defer) => {
|
|
95
|
+
defer.resolve(null);
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Finds the Defer for the specified item and resolves its promise
|
|
101
|
+
* @param {Object} item
|
|
102
|
+
* @returns {Promise<undefined>}
|
|
103
|
+
*/
|
|
104
|
+
handleItemSuccess(item) {
|
|
105
|
+
return this.getDeferredForResponse(item).then((defer) => {
|
|
106
|
+
defer.resolve(item.entity);
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns a promise with the unique key for the item
|
|
112
|
+
* @param {Object} item
|
|
113
|
+
* @returns {Promise}
|
|
114
|
+
*/
|
|
115
|
+
fingerprintRequest(item) {
|
|
116
|
+
return Promise.resolve(item);
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Returns a promise with the unique key for the item
|
|
121
|
+
* @param {Object} item
|
|
122
|
+
* @returns {Promise}
|
|
123
|
+
*/
|
|
124
|
+
fingerprintResponse(item) {
|
|
125
|
+
return Promise.resolve(item.requestValue);
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export default DssBatcher;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {Exception} from '@webex/common';
|
|
2
|
+
import {RequestOptions} from './types';
|
|
3
|
+
|
|
4
|
+
interface DssTimeoutErrorParams extends Required<Pick<RequestOptions, 'resource' | 'params'>> {
|
|
5
|
+
requestId: string;
|
|
6
|
+
timeout: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Thrown when an expected DSS respond is not received in a timely manner.
|
|
11
|
+
*/
|
|
12
|
+
export class DssTimeoutError extends Exception {
|
|
13
|
+
/**
|
|
14
|
+
* Construct DssTimeoutError
|
|
15
|
+
* @param {DssTimeoutErrorParams} details
|
|
16
|
+
*/
|
|
17
|
+
// eslint-disable-next-line no-useless-constructor
|
|
18
|
+
constructor(details: DssTimeoutErrorParams) {
|
|
19
|
+
super(details);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parse Error details
|
|
24
|
+
*
|
|
25
|
+
* @param {DssTimeoutErrorParams} details
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
parse(details: DssTimeoutErrorParams) {
|
|
29
|
+
return (
|
|
30
|
+
`The DSS did not respond within ${details.timeout} ms.` +
|
|
31
|
+
`\n Request Id: ${details.requestId}` +
|
|
32
|
+
`\n Resource: ${details.resource}` +
|
|
33
|
+
`\n Params: ${JSON.stringify(details.params)}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/dss.ts
CHANGED
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
/*!
|
|
3
3
|
* Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
|
|
4
4
|
*/
|
|
5
|
+
/* eslint-disable no-underscore-dangle */
|
|
5
6
|
import uuid from 'uuid';
|
|
6
7
|
import {WebexPlugin} from '@webex/webex-core';
|
|
7
8
|
import '@webex/internal-plugin-mercury';
|
|
8
9
|
import {range, isEqual, get} from 'lodash';
|
|
9
|
-
import type {SearchOptions, LookupDetailOptions, LookupOptions, LookupByEmailOptions} from './types';
|
|
10
10
|
|
|
11
|
+
import {Timer} from '@webex/common-timers';
|
|
12
|
+
import type {
|
|
13
|
+
SearchOptions,
|
|
14
|
+
LookupDetailOptions,
|
|
15
|
+
LookupOptions,
|
|
16
|
+
LookupByEmailOptions,
|
|
17
|
+
SearchPlaceOptions,
|
|
18
|
+
} from './types';
|
|
11
19
|
import {
|
|
12
20
|
DSS_REGISTERED,
|
|
13
21
|
DSS_UNREGISTERED,
|
|
@@ -16,7 +24,15 @@ import {
|
|
|
16
24
|
DSS_SERVICE_NAME,
|
|
17
25
|
DSS_SEARCH_MERCURY_EVENT,
|
|
18
26
|
DSS_RESULT,
|
|
27
|
+
LOOKUP_DATA_PATH,
|
|
28
|
+
LOOKUP_FOUND_PATH,
|
|
29
|
+
LOOKUP_NOT_FOUND_PATH,
|
|
30
|
+
LOOKUP_REQUEST_KEY,
|
|
31
|
+
SEARCH_DATA_PATH,
|
|
19
32
|
} from './constants';
|
|
33
|
+
import DssBatcher from './dss-batcher';
|
|
34
|
+
import {DssTimeoutError} from './dss-errors';
|
|
35
|
+
import {BatcherOptions, RequestOptions, RequestResult} from './types';
|
|
20
36
|
|
|
21
37
|
const DSS = WebexPlugin.extend({
|
|
22
38
|
namespace: 'DSS',
|
|
@@ -29,6 +45,18 @@ const DSS = WebexPlugin.extend({
|
|
|
29
45
|
*/
|
|
30
46
|
registered: false,
|
|
31
47
|
|
|
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
|
+
|
|
32
60
|
/**
|
|
33
61
|
* Explicitly sets up the DSS plugin by connecting to mercury, and listening for DSS events.
|
|
34
62
|
* @returns {Promise}
|
|
@@ -48,7 +76,8 @@ const DSS = WebexPlugin.extend({
|
|
|
48
76
|
return Promise.resolve();
|
|
49
77
|
}
|
|
50
78
|
|
|
51
|
-
return this.webex.internal.mercury
|
|
79
|
+
return this.webex.internal.mercury
|
|
80
|
+
.connect()
|
|
52
81
|
.then(() => {
|
|
53
82
|
this.listenForEvents();
|
|
54
83
|
this.trigger(DSS_REGISTERED);
|
|
@@ -76,11 +105,10 @@ const DSS = WebexPlugin.extend({
|
|
|
76
105
|
|
|
77
106
|
this.stopListeningForEvents();
|
|
78
107
|
|
|
79
|
-
return this.webex.internal.mercury.disconnect()
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
108
|
+
return this.webex.internal.mercury.disconnect().then(() => {
|
|
109
|
+
this.trigger(DSS_UNREGISTERED);
|
|
110
|
+
this.registered = false;
|
|
111
|
+
});
|
|
84
112
|
},
|
|
85
113
|
|
|
86
114
|
/**
|
|
@@ -108,6 +136,7 @@ const DSS = WebexPlugin.extend({
|
|
|
108
136
|
},
|
|
109
137
|
|
|
110
138
|
/**
|
|
139
|
+
* constructs the event name based on request id
|
|
111
140
|
* @param {UUID} requestId the id of the request
|
|
112
141
|
* @returns {string}
|
|
113
142
|
*/
|
|
@@ -116,6 +145,7 @@ const DSS = WebexPlugin.extend({
|
|
|
116
145
|
},
|
|
117
146
|
|
|
118
147
|
/**
|
|
148
|
+
* Takes incoming data and triggers correct events
|
|
119
149
|
* @param {Object} data the event data
|
|
120
150
|
* @returns {undefined}
|
|
121
151
|
*/
|
|
@@ -125,43 +155,81 @@ const DSS = WebexPlugin.extend({
|
|
|
125
155
|
},
|
|
126
156
|
|
|
127
157
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
158
|
+
* Makes the request to the directory service
|
|
159
|
+
* @param {Object} options
|
|
160
|
+
* @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
|
|
170
|
+
*/
|
|
171
|
+
_request(options: RequestOptions): Promise<RequestResult> {
|
|
172
|
+
const {resource, params, dataPath, foundPath, notFoundPath} = options;
|
|
137
173
|
|
|
174
|
+
const timeout = this.config.requestTimeout;
|
|
138
175
|
const requestId = uuid.v4();
|
|
139
176
|
const eventName = this._getResultEventName(requestId);
|
|
140
177
|
const result = {};
|
|
141
|
-
let expectedSeqNums;
|
|
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);
|
|
142
186
|
|
|
143
|
-
return new Promise((resolve) => {
|
|
144
187
|
this.listenTo(this, eventName, (data) => {
|
|
145
|
-
|
|
188
|
+
timer.reset();
|
|
189
|
+
const resultData = get(data, dataPath, []);
|
|
190
|
+
let found;
|
|
146
191
|
|
|
147
|
-
|
|
192
|
+
if (foundPath) {
|
|
193
|
+
found = get(data, foundPath, []);
|
|
194
|
+
}
|
|
195
|
+
result[data.sequence] = foundPath ? {resultData, found} : {resultData};
|
|
148
196
|
|
|
149
197
|
if (data.finished) {
|
|
150
198
|
expectedSeqNums = range(data.sequence + 1).map(String);
|
|
199
|
+
if (notFoundPath) {
|
|
200
|
+
notFoundArray = get(data, notFoundPath, []);
|
|
201
|
+
}
|
|
151
202
|
}
|
|
152
203
|
|
|
153
204
|
const done = isEqual(expectedSeqNums, Object.keys(result));
|
|
154
205
|
|
|
155
206
|
if (done) {
|
|
156
|
-
|
|
207
|
+
timer.cancel();
|
|
208
|
+
|
|
209
|
+
const resultArray: any[] = [];
|
|
210
|
+
const foundArray: any[] = [];
|
|
211
|
+
|
|
157
212
|
expectedSeqNums.forEach((index) => {
|
|
158
213
|
const seqResult = result[index];
|
|
214
|
+
|
|
159
215
|
if (seqResult) {
|
|
160
|
-
resultArray.push(...seqResult);
|
|
216
|
+
resultArray.push(...seqResult.resultData);
|
|
217
|
+
if (foundPath) {
|
|
218
|
+
foundArray.push(...seqResult.found);
|
|
219
|
+
}
|
|
161
220
|
}
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
|
|
221
|
+
});
|
|
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);
|
|
165
233
|
this.stopListening(this, eventName);
|
|
166
234
|
}
|
|
167
235
|
});
|
|
@@ -170,62 +238,130 @@ const DSS = WebexPlugin.extend({
|
|
|
170
238
|
resource,
|
|
171
239
|
method: 'POST',
|
|
172
240
|
contentType: 'application/json',
|
|
173
|
-
body: {requestId, ...params}
|
|
241
|
+
body: {requestId, ...params},
|
|
174
242
|
});
|
|
243
|
+
timer.start();
|
|
175
244
|
});
|
|
176
245
|
},
|
|
177
246
|
|
|
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
|
+
|
|
178
276
|
/**
|
|
179
277
|
* Retrieves detailed information about an entity
|
|
180
278
|
* @param {Object} options
|
|
181
279
|
* @param {UUID} options.id the id of the entity to lookup
|
|
182
|
-
* @returns {Promise} Resolves with
|
|
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
|
|
183
282
|
*/
|
|
184
283
|
lookupDetail(options: LookupDetailOptions) {
|
|
185
284
|
const {id} = options;
|
|
186
285
|
|
|
286
|
+
const resource = `/lookup/orgid/${this.webex.internal.device.orgId}/identity/${id}/detail`;
|
|
287
|
+
|
|
187
288
|
return this._request({
|
|
188
|
-
dataPath:
|
|
189
|
-
|
|
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;
|
|
190
299
|
});
|
|
191
300
|
},
|
|
192
301
|
|
|
193
302
|
/**
|
|
194
|
-
* Retrieves basic information about
|
|
303
|
+
* Retrieves basic information about an entity within an organization
|
|
195
304
|
* @param {Object} options
|
|
196
|
-
* @param {UUID} options.
|
|
197
|
-
* @param {UUID} options.entityProviderType the provider to query
|
|
198
|
-
* @
|
|
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
|
|
199
310
|
*/
|
|
200
311
|
lookup(options: LookupOptions) {
|
|
201
|
-
const {
|
|
312
|
+
const {id, entityProviderType, shouldBatch = true} = options;
|
|
202
313
|
|
|
203
|
-
const resource = entityProviderType
|
|
314
|
+
const resource = entityProviderType
|
|
315
|
+
? `/lookup/orgid/${this.webex.internal.device.orgId}/entityprovidertype/${entityProviderType}`
|
|
316
|
+
: `/lookup/orgid/${this.webex.internal.device.orgId}/identities`;
|
|
317
|
+
|
|
318
|
+
if (shouldBatch) {
|
|
319
|
+
return this._batchedLookup({
|
|
320
|
+
resource,
|
|
321
|
+
lookupValue: id,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
204
324
|
|
|
205
325
|
return this._request({
|
|
206
|
-
dataPath:
|
|
326
|
+
dataPath: LOOKUP_DATA_PATH,
|
|
327
|
+
foundPath: LOOKUP_FOUND_PATH,
|
|
207
328
|
resource,
|
|
208
329
|
params: {
|
|
209
|
-
|
|
330
|
+
[LOOKUP_REQUEST_KEY]: [id],
|
|
331
|
+
},
|
|
332
|
+
}).then(({resultArray, foundArray}) => {
|
|
333
|
+
if (foundArray[0] === id) {
|
|
334
|
+
return resultArray[0];
|
|
210
335
|
}
|
|
336
|
+
|
|
337
|
+
return null;
|
|
211
338
|
});
|
|
212
339
|
},
|
|
213
340
|
|
|
214
341
|
/**
|
|
215
|
-
* Retrieves basic information about
|
|
342
|
+
* Retrieves basic information about an enitity within an organization
|
|
216
343
|
* @param {Object} options
|
|
217
|
-
* @param {UUID} options.
|
|
218
|
-
* @returns {Promise} Resolves with
|
|
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
|
|
219
347
|
*/
|
|
220
348
|
lookupByEmail(options: LookupByEmailOptions) {
|
|
221
|
-
const {
|
|
349
|
+
const {email} = options;
|
|
350
|
+
const resource = `/lookup/orgid/${this.webex.internal.device.orgId}/emails`;
|
|
222
351
|
|
|
223
352
|
return this._request({
|
|
224
|
-
dataPath:
|
|
225
|
-
|
|
353
|
+
dataPath: LOOKUP_DATA_PATH,
|
|
354
|
+
foundPath: LOOKUP_FOUND_PATH,
|
|
355
|
+
resource,
|
|
226
356
|
params: {
|
|
227
|
-
|
|
357
|
+
[LOOKUP_REQUEST_KEY]: [email],
|
|
358
|
+
},
|
|
359
|
+
}).then(({resultArray, foundArray}) => {
|
|
360
|
+
if (foundArray[0] === email) {
|
|
361
|
+
return resultArray[0];
|
|
228
362
|
}
|
|
363
|
+
|
|
364
|
+
return null;
|
|
229
365
|
});
|
|
230
366
|
},
|
|
231
367
|
|
|
@@ -236,23 +372,46 @@ const DSS = WebexPlugin.extend({
|
|
|
236
372
|
* @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
|
|
237
373
|
* @param {number} options.resultSize The maximum number of results returned from each provider
|
|
238
374
|
* @returns {Promise} Resolves with an array of entities found
|
|
375
|
+
* @throws {DssTimeoutError} when server does not respond in the specified timeframe
|
|
239
376
|
*/
|
|
240
377
|
search(options: SearchOptions) {
|
|
241
|
-
const {
|
|
242
|
-
requestedTypes, resultSize, queryString
|
|
243
|
-
} = options;
|
|
378
|
+
const {requestedTypes, resultSize, queryString} = options;
|
|
244
379
|
|
|
245
380
|
return this._request({
|
|
246
|
-
dataPath:
|
|
381
|
+
dataPath: SEARCH_DATA_PATH,
|
|
247
382
|
resource: `/search/orgid/${this.webex.internal.device.orgId}/entities`,
|
|
248
383
|
params: {
|
|
249
384
|
queryString,
|
|
250
385
|
resultSize,
|
|
251
|
-
requestedTypes
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
386
|
+
requestedTypes,
|
|
387
|
+
},
|
|
388
|
+
}).then(({resultArray}) => resultArray);
|
|
389
|
+
},
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Search for information about places
|
|
393
|
+
* @param {Object} options
|
|
394
|
+
* @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.
|
|
395
|
+
* @param {number} options.resultSize The maximum number of results returned from each provider
|
|
396
|
+
* @returns {Promise} Resolves with an array of entities found
|
|
397
|
+
*/
|
|
398
|
+
searchPlaces(options: SearchPlaceOptions) {
|
|
399
|
+
const {resultSize, queryString, isOnlySchedulableRooms} = options;
|
|
255
400
|
|
|
401
|
+
return this._request({
|
|
402
|
+
dataPath: 'directoryEntities',
|
|
403
|
+
resource: `/search/orgid/${this.webex.internal.device.orgId}/places`,
|
|
404
|
+
params: {
|
|
405
|
+
queryString,
|
|
406
|
+
resultSize,
|
|
407
|
+
isOnlySchedulableRooms,
|
|
408
|
+
},
|
|
409
|
+
}).catch((error) => {
|
|
410
|
+
this.logger.error(`DSS->search place#ERROR, search place failure, ${error.message}`);
|
|
411
|
+
|
|
412
|
+
return Promise.reject(error);
|
|
413
|
+
});
|
|
414
|
+
},
|
|
256
415
|
});
|
|
257
416
|
|
|
258
417
|
export default DSS;
|
package/src/index.ts
CHANGED