@webex/internal-plugin-lyra 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/space.js CHANGED
@@ -1,367 +1,367 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import querystring from 'querystring';
6
-
7
- import {WebexPlugin} from '@webex/webex-core';
8
- import {base64} from '@webex/common';
9
-
10
- /**
11
- * @class
12
- * @extends {Lyra}
13
- * @memberof Lyra
14
- */
15
- const Space = WebexPlugin.extend({
16
- namespace: 'Lyra',
17
-
18
- /**
19
- * Lists lyra spaces associated with user
20
- *
21
- * @returns {Promise<Array>} spaces
22
- */
23
- list() {
24
- return this.webex
25
- .request({
26
- method: 'GET',
27
- api: 'lyra',
28
- resource: '/spaces',
29
- })
30
- .then((res) => res.body.items);
31
- },
32
-
33
- /**
34
- * Retrieves a lyra space info
35
- * @param {Types~LyraSpace} space
36
- * @param {string} space.id
37
- * @param {string} space.identity.id
38
- * @returns {Promise<LyraSpace>} response body
39
- */
40
- get(space = {}) {
41
- const spaceId = space.id || (space.identity && space.identity.id);
42
-
43
- if (!spaceId) {
44
- return Promise.reject(new Error('space.id is required'));
45
- }
46
-
47
- return this.webex
48
- .request({
49
- method: 'GET',
50
- api: 'lyra',
51
- resource: `/spaces/${spaceId}`,
52
- })
53
- .then((res) => res.body);
54
- },
55
-
56
- /**
57
- * Joins a lyra space, update every 10 minutes to keep alive for MANUAL
58
- * @param {Types~LyraSpace} space
59
- * @param {string} space.url
60
- * @param {object} options
61
- * @param {string} options.passType
62
- * @param {string} options.data additional data such as proof for ultrasound
63
- * @param {string} options.uri use a custom uri
64
- * @returns {Promise}
65
- */
66
- join(space, options) {
67
- options = {
68
- passType: 'MANUAL',
69
- ...options,
70
- };
71
-
72
- const body = {
73
- pass: {
74
- type: options.passType,
75
- },
76
- deviceUrl: this.webex.internal.device.url,
77
- };
78
-
79
- if (options.data) {
80
- body.pass.data = options.data;
81
- }
82
-
83
- if (options.verificationInitiation) {
84
- body.verificationInitiation = options.verificationInitiation;
85
- }
86
-
87
- // if options.uri is available use it, since that would have the
88
- // complete lyra service URL
89
- if (options.uri) {
90
- return this.webex.request({
91
- method: 'PUT',
92
- uri: options.uri,
93
- body,
94
- });
95
- }
96
-
97
- return this.webex.request({
98
- method: 'PUT',
99
- api: 'lyra',
100
- resource: `${space.url}/occupants/@me`,
101
- body,
102
- });
103
- },
104
-
105
- /**
106
- * Leaves a lyra space
107
- * @param {Types~LyraSpace} space
108
- * @param {string} space.url
109
- * @param {object} options
110
- * @param {boolean} options.removeAllDevices remove all devices of current user also
111
- * @returns {Promise}
112
- */
113
- leave(space, options = {}) {
114
- // all devices are removed by default (when deviceUrl is not supplied)
115
- let uri = `${space.url}/occupants/@me`;
116
-
117
- if (!options.removeAllDevices) {
118
- const params = {
119
- deviceUrl: base64.toBase64Url(this.webex.internal.device.url),
120
- };
121
-
122
- uri += `?${querystring.stringify(params)}`;
123
- }
124
-
125
- return this.webex.request({
126
- method: 'DELETE',
127
- api: 'lyra',
128
- resource: uri,
129
- });
130
- },
131
-
132
- /**
133
- * Verifies a space occupant (to be used by the lyra device)
134
- * @param {Types~LyraSpace} space
135
- * @param {string} space.url
136
- * @param {string} occupantId id of user to verify
137
- * @returns {Promise}
138
- */
139
- verifyOccupant(space, occupantId) {
140
- const body = {
141
- pass: {
142
- type: 'VERIFICATION',
143
- },
144
- };
145
-
146
- return this.webex.request({
147
- method: 'PUT',
148
- uri: `${space.url}/occupants/${occupantId}`,
149
- body,
150
- });
151
- },
152
-
153
- /**
154
- * Gets the state of bindings in this Lyra space
155
- * @param {Types~LyraSpace} space
156
- * @param {string} space.url
157
- * @returns {Promise<LyraBindings>} bindings response body
158
- */
159
- getCurrentBindings(space) {
160
- return this.webex
161
- .request({
162
- method: 'GET',
163
- uri: `${space.url}/bindings`,
164
- })
165
- .then((res) => res.body);
166
- },
167
-
168
- /**
169
- * Binds a conversation to lyra space
170
- * @param {Types~LyraSpace} space
171
- * @param {string} space.url
172
- * @param {string} space.id
173
- * @param {string} space.identity.id
174
- * @param {Types~Conversation} conversation
175
- * @param {string} conversation.kmsResourceObjectUrl
176
- * @param {string} conversation.url
177
- * @param {object} options
178
- * @param {boolean} options.uri complete lyra service URL
179
- * @returns {Promise<LyraBindings>} bindings response body
180
- */
181
- bindConversation(space = {}, conversation = {}, options = {}) {
182
- const spaceId = space.id || (space.identity && space.identity.id);
183
-
184
- if (!space.url) {
185
- return Promise.reject(new Error('space.url is required'));
186
- }
187
-
188
- if (!spaceId) {
189
- return Promise.reject(new Error('space.id is required'));
190
- }
191
-
192
- if (!conversation.kmsResourceObjectUrl) {
193
- return Promise.reject(new Error('conversation.kmsResourceObjectUrl is required'));
194
- }
195
-
196
- if (!conversation.url) {
197
- return Promise.reject(new Error('conversation.url is required'));
198
- }
199
-
200
- const body = {
201
- kmsMessage: {
202
- method: 'create',
203
- uri: '/authorizations',
204
- resourceUri: `${conversation.kmsResourceObjectUrl}`,
205
- userIds: [spaceId],
206
- },
207
- conversationUrl: conversation.url,
208
- };
209
-
210
- const request = {
211
- method: 'POST',
212
- body,
213
- };
214
-
215
- // if options.uri is available use it, since that would have the
216
- // complete lyra service URL
217
- if (options.uri) {
218
- request.uri = options.uri;
219
- } else {
220
- request.api = 'lyra';
221
- request.resource = `${space.url}/bindings`;
222
- }
223
-
224
- return this._bindConversation(spaceId)
225
- .then(() => this.webex.request(request))
226
- .then((res) => res.body);
227
- },
228
-
229
- /**
230
- * Binds a conversation to lyra space by posting capabilities to Lyra.
231
- *
232
- * Lyra no longer automatically enables binding for a space containing a device with type "SPARK_BOARD".
233
- * Webexboard now is running the CE code stack which supports posting of capabilities to Lyra.
234
- * @param {String} spaceId space ID
235
- * @returns {Promise<LyraBindings>} bindings response body
236
- */
237
- _bindConversation(spaceId) {
238
- // Skip until we can bind a conversation to lyra space by posting capabilities to Lyra.
239
- /* eslint no-unreachable: 1 */
240
- return Promise.resolve();
241
-
242
- // PUT /lyra/api/v1/spaces/{spaceId}/devices/{encodedDeviceUrl}/capabilities
243
- const encodedDeviceUrl = base64.encode(this.webex.internal.device.url);
244
- const resource = `spaces/${spaceId}/devices/${encodedDeviceUrl}/capabilities`;
245
-
246
- return this.webex.request({
247
- method: 'PUT',
248
- api: 'lyra',
249
- resource,
250
- body: {
251
- bindingCleanupAfterCall: true,
252
- },
253
- });
254
- },
255
-
256
- /**
257
- * Removes binding between a conversation and a lyra space using conversation
258
- * url
259
- * @param {Types~LyraSpace} space
260
- * @param {string} space.url
261
- * @param {string} space.id
262
- * @param {string} space.identity.id
263
- * @param {Types~Conversation} conversation
264
- * @param {string} conversation.kmsResourceObjectUrl
265
- * @param {string} conversation.url
266
- * @param {object} options
267
- * @param {boolean} options.uri complete lyra service URL
268
- * @returns {Promise<LyraBindings>} bindings response body
269
- */
270
- unbindConversation(space = {}, conversation = {}, options = {}) {
271
- const spaceId = space.id || (space.identity && space.identity.id);
272
-
273
- if (!space.url) {
274
- return Promise.reject(new Error('space.url is required'));
275
- }
276
-
277
- if (!spaceId) {
278
- return Promise.reject(new Error('space.id is required'));
279
- }
280
-
281
- if (!conversation.url) {
282
- return Promise.reject(new Error('conversation.url is required'));
283
- }
284
-
285
- if (!conversation.kmsResourceObjectUrl) {
286
- return Promise.reject(new Error('conversation.kmsResourceObjectUrl is required'));
287
- }
288
-
289
- const parameters = {
290
- kmsMessage: {
291
- method: 'delete',
292
- uri: `${conversation.kmsResourceObjectUrl}/authorizations?${querystring.stringify({
293
- authId: spaceId,
294
- })}`,
295
- },
296
- conversationUrl: base64.toBase64Url(conversation.url),
297
- };
298
-
299
- return this.webex.internal.encryption.kms.prepareRequest(parameters.kmsMessage).then((req) => {
300
- parameters.kmsMessage = req.wrapped;
301
- // if options.uri is available use it, since that would have the
302
- // complete lyra service URL
303
- if (options.uri) {
304
- return this.webex.request({
305
- method: 'DELETE',
306
- uri: `${options.uri}?${querystring.stringify(parameters)}`,
307
- });
308
- }
309
-
310
- return this.webex.request({
311
- method: 'DELETE',
312
- api: 'lyra',
313
- resource: `${space.url}/bindings?${querystring.stringify(parameters)}`,
314
- });
315
- });
316
- },
317
-
318
- /**
319
- * Delete a binding using binding id
320
- * @param {Types~LyraSpace} space
321
- * @param {string} space.url
322
- * @param {string} space.identity.id
323
- * @param {object} options
324
- * @param {string} options.kmsResourceObjectUrl
325
- * @param {string} options.bindingId
326
- * @returns {Promise<LyraBindings>} bindings response body
327
- */
328
- deleteBinding(space = {}, options = {}) {
329
- const spaceId = space.id || (space.identity && space.identity.id);
330
-
331
- if (!space.url) {
332
- return Promise.reject(new Error('space.url is required'));
333
- }
334
-
335
- if (!spaceId) {
336
- return Promise.reject(new Error('space.id is required'));
337
- }
338
-
339
- if (!options.kmsResourceObjectUrl) {
340
- return Promise.reject(new Error('options.kmsResourceObjectUrl is required'));
341
- }
342
-
343
- if (!options.bindingId) {
344
- return Promise.reject(new Error('options.bindingId is required'));
345
- }
346
-
347
- const parameters = {
348
- kmsMessage: {
349
- method: 'delete',
350
- uri: `${options.kmsResourceObjectUrl}/authorizations?${querystring.stringify({
351
- authId: spaceId,
352
- })}`,
353
- },
354
- };
355
-
356
- return this.webex.internal.encryption.kms.prepareRequest(parameters.kmsMessage).then((req) => {
357
- parameters.kmsMessage = req.wrapped;
358
-
359
- return this.webex.request({
360
- method: 'DELETE',
361
- uri: `${space.url}/bindings/${options.bindingId}?${querystring.stringify(parameters)}`,
362
- });
363
- });
364
- },
365
- });
366
-
367
- export default Space;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import querystring from 'querystring';
6
+
7
+ import {WebexPlugin} from '@webex/webex-core';
8
+ import {base64} from '@webex/common';
9
+
10
+ /**
11
+ * @class
12
+ * @extends {Lyra}
13
+ * @memberof Lyra
14
+ */
15
+ const Space = WebexPlugin.extend({
16
+ namespace: 'Lyra',
17
+
18
+ /**
19
+ * Lists lyra spaces associated with user
20
+ *
21
+ * @returns {Promise<Array>} spaces
22
+ */
23
+ list() {
24
+ return this.webex
25
+ .request({
26
+ method: 'GET',
27
+ api: 'lyra',
28
+ resource: '/spaces',
29
+ })
30
+ .then((res) => res.body.items);
31
+ },
32
+
33
+ /**
34
+ * Retrieves a lyra space info
35
+ * @param {Types~LyraSpace} space
36
+ * @param {string} space.id
37
+ * @param {string} space.identity.id
38
+ * @returns {Promise<LyraSpace>} response body
39
+ */
40
+ get(space = {}) {
41
+ const spaceId = space.id || (space.identity && space.identity.id);
42
+
43
+ if (!spaceId) {
44
+ return Promise.reject(new Error('space.id is required'));
45
+ }
46
+
47
+ return this.webex
48
+ .request({
49
+ method: 'GET',
50
+ api: 'lyra',
51
+ resource: `/spaces/${spaceId}`,
52
+ })
53
+ .then((res) => res.body);
54
+ },
55
+
56
+ /**
57
+ * Joins a lyra space, update every 10 minutes to keep alive for MANUAL
58
+ * @param {Types~LyraSpace} space
59
+ * @param {string} space.url
60
+ * @param {object} options
61
+ * @param {string} options.passType
62
+ * @param {string} options.data additional data such as proof for ultrasound
63
+ * @param {string} options.uri use a custom uri
64
+ * @returns {Promise}
65
+ */
66
+ join(space, options) {
67
+ options = {
68
+ passType: 'MANUAL',
69
+ ...options,
70
+ };
71
+
72
+ const body = {
73
+ pass: {
74
+ type: options.passType,
75
+ },
76
+ deviceUrl: this.webex.internal.device.url,
77
+ };
78
+
79
+ if (options.data) {
80
+ body.pass.data = options.data;
81
+ }
82
+
83
+ if (options.verificationInitiation) {
84
+ body.verificationInitiation = options.verificationInitiation;
85
+ }
86
+
87
+ // if options.uri is available use it, since that would have the
88
+ // complete lyra service URL
89
+ if (options.uri) {
90
+ return this.webex.request({
91
+ method: 'PUT',
92
+ uri: options.uri,
93
+ body,
94
+ });
95
+ }
96
+
97
+ return this.webex.request({
98
+ method: 'PUT',
99
+ api: 'lyra',
100
+ resource: `${space.url}/occupants/@me`,
101
+ body,
102
+ });
103
+ },
104
+
105
+ /**
106
+ * Leaves a lyra space
107
+ * @param {Types~LyraSpace} space
108
+ * @param {string} space.url
109
+ * @param {object} options
110
+ * @param {boolean} options.removeAllDevices remove all devices of current user also
111
+ * @returns {Promise}
112
+ */
113
+ leave(space, options = {}) {
114
+ // all devices are removed by default (when deviceUrl is not supplied)
115
+ let uri = `${space.url}/occupants/@me`;
116
+
117
+ if (!options.removeAllDevices) {
118
+ const params = {
119
+ deviceUrl: base64.toBase64Url(this.webex.internal.device.url),
120
+ };
121
+
122
+ uri += `?${querystring.stringify(params)}`;
123
+ }
124
+
125
+ return this.webex.request({
126
+ method: 'DELETE',
127
+ api: 'lyra',
128
+ resource: uri,
129
+ });
130
+ },
131
+
132
+ /**
133
+ * Verifies a space occupant (to be used by the lyra device)
134
+ * @param {Types~LyraSpace} space
135
+ * @param {string} space.url
136
+ * @param {string} occupantId id of user to verify
137
+ * @returns {Promise}
138
+ */
139
+ verifyOccupant(space, occupantId) {
140
+ const body = {
141
+ pass: {
142
+ type: 'VERIFICATION',
143
+ },
144
+ };
145
+
146
+ return this.webex.request({
147
+ method: 'PUT',
148
+ uri: `${space.url}/occupants/${occupantId}`,
149
+ body,
150
+ });
151
+ },
152
+
153
+ /**
154
+ * Gets the state of bindings in this Lyra space
155
+ * @param {Types~LyraSpace} space
156
+ * @param {string} space.url
157
+ * @returns {Promise<LyraBindings>} bindings response body
158
+ */
159
+ getCurrentBindings(space) {
160
+ return this.webex
161
+ .request({
162
+ method: 'GET',
163
+ uri: `${space.url}/bindings`,
164
+ })
165
+ .then((res) => res.body);
166
+ },
167
+
168
+ /**
169
+ * Binds a conversation to lyra space
170
+ * @param {Types~LyraSpace} space
171
+ * @param {string} space.url
172
+ * @param {string} space.id
173
+ * @param {string} space.identity.id
174
+ * @param {Types~Conversation} conversation
175
+ * @param {string} conversation.kmsResourceObjectUrl
176
+ * @param {string} conversation.url
177
+ * @param {object} options
178
+ * @param {boolean} options.uri complete lyra service URL
179
+ * @returns {Promise<LyraBindings>} bindings response body
180
+ */
181
+ bindConversation(space = {}, conversation = {}, options = {}) {
182
+ const spaceId = space.id || (space.identity && space.identity.id);
183
+
184
+ if (!space.url) {
185
+ return Promise.reject(new Error('space.url is required'));
186
+ }
187
+
188
+ if (!spaceId) {
189
+ return Promise.reject(new Error('space.id is required'));
190
+ }
191
+
192
+ if (!conversation.kmsResourceObjectUrl) {
193
+ return Promise.reject(new Error('conversation.kmsResourceObjectUrl is required'));
194
+ }
195
+
196
+ if (!conversation.url) {
197
+ return Promise.reject(new Error('conversation.url is required'));
198
+ }
199
+
200
+ const body = {
201
+ kmsMessage: {
202
+ method: 'create',
203
+ uri: '/authorizations',
204
+ resourceUri: `${conversation.kmsResourceObjectUrl}`,
205
+ userIds: [spaceId],
206
+ },
207
+ conversationUrl: conversation.url,
208
+ };
209
+
210
+ const request = {
211
+ method: 'POST',
212
+ body,
213
+ };
214
+
215
+ // if options.uri is available use it, since that would have the
216
+ // complete lyra service URL
217
+ if (options.uri) {
218
+ request.uri = options.uri;
219
+ } else {
220
+ request.api = 'lyra';
221
+ request.resource = `${space.url}/bindings`;
222
+ }
223
+
224
+ return this._bindConversation(spaceId)
225
+ .then(() => this.webex.request(request))
226
+ .then((res) => res.body);
227
+ },
228
+
229
+ /**
230
+ * Binds a conversation to lyra space by posting capabilities to Lyra.
231
+ *
232
+ * Lyra no longer automatically enables binding for a space containing a device with type "SPARK_BOARD".
233
+ * Webexboard now is running the CE code stack which supports posting of capabilities to Lyra.
234
+ * @param {String} spaceId space ID
235
+ * @returns {Promise<LyraBindings>} bindings response body
236
+ */
237
+ _bindConversation(spaceId) {
238
+ // Skip until we can bind a conversation to lyra space by posting capabilities to Lyra.
239
+ /* eslint no-unreachable: 1 */
240
+ return Promise.resolve();
241
+
242
+ // PUT /lyra/api/v1/spaces/{spaceId}/devices/{encodedDeviceUrl}/capabilities
243
+ const encodedDeviceUrl = base64.encode(this.webex.internal.device.url);
244
+ const resource = `spaces/${spaceId}/devices/${encodedDeviceUrl}/capabilities`;
245
+
246
+ return this.webex.request({
247
+ method: 'PUT',
248
+ api: 'lyra',
249
+ resource,
250
+ body: {
251
+ bindingCleanupAfterCall: true,
252
+ },
253
+ });
254
+ },
255
+
256
+ /**
257
+ * Removes binding between a conversation and a lyra space using conversation
258
+ * url
259
+ * @param {Types~LyraSpace} space
260
+ * @param {string} space.url
261
+ * @param {string} space.id
262
+ * @param {string} space.identity.id
263
+ * @param {Types~Conversation} conversation
264
+ * @param {string} conversation.kmsResourceObjectUrl
265
+ * @param {string} conversation.url
266
+ * @param {object} options
267
+ * @param {boolean} options.uri complete lyra service URL
268
+ * @returns {Promise<LyraBindings>} bindings response body
269
+ */
270
+ unbindConversation(space = {}, conversation = {}, options = {}) {
271
+ const spaceId = space.id || (space.identity && space.identity.id);
272
+
273
+ if (!space.url) {
274
+ return Promise.reject(new Error('space.url is required'));
275
+ }
276
+
277
+ if (!spaceId) {
278
+ return Promise.reject(new Error('space.id is required'));
279
+ }
280
+
281
+ if (!conversation.url) {
282
+ return Promise.reject(new Error('conversation.url is required'));
283
+ }
284
+
285
+ if (!conversation.kmsResourceObjectUrl) {
286
+ return Promise.reject(new Error('conversation.kmsResourceObjectUrl is required'));
287
+ }
288
+
289
+ const parameters = {
290
+ kmsMessage: {
291
+ method: 'delete',
292
+ uri: `${conversation.kmsResourceObjectUrl}/authorizations?${querystring.stringify({
293
+ authId: spaceId,
294
+ })}`,
295
+ },
296
+ conversationUrl: base64.toBase64Url(conversation.url),
297
+ };
298
+
299
+ return this.webex.internal.encryption.kms.prepareRequest(parameters.kmsMessage).then((req) => {
300
+ parameters.kmsMessage = req.wrapped;
301
+ // if options.uri is available use it, since that would have the
302
+ // complete lyra service URL
303
+ if (options.uri) {
304
+ return this.webex.request({
305
+ method: 'DELETE',
306
+ uri: `${options.uri}?${querystring.stringify(parameters)}`,
307
+ });
308
+ }
309
+
310
+ return this.webex.request({
311
+ method: 'DELETE',
312
+ api: 'lyra',
313
+ resource: `${space.url}/bindings?${querystring.stringify(parameters)}`,
314
+ });
315
+ });
316
+ },
317
+
318
+ /**
319
+ * Delete a binding using binding id
320
+ * @param {Types~LyraSpace} space
321
+ * @param {string} space.url
322
+ * @param {string} space.identity.id
323
+ * @param {object} options
324
+ * @param {string} options.kmsResourceObjectUrl
325
+ * @param {string} options.bindingId
326
+ * @returns {Promise<LyraBindings>} bindings response body
327
+ */
328
+ deleteBinding(space = {}, options = {}) {
329
+ const spaceId = space.id || (space.identity && space.identity.id);
330
+
331
+ if (!space.url) {
332
+ return Promise.reject(new Error('space.url is required'));
333
+ }
334
+
335
+ if (!spaceId) {
336
+ return Promise.reject(new Error('space.id is required'));
337
+ }
338
+
339
+ if (!options.kmsResourceObjectUrl) {
340
+ return Promise.reject(new Error('options.kmsResourceObjectUrl is required'));
341
+ }
342
+
343
+ if (!options.bindingId) {
344
+ return Promise.reject(new Error('options.bindingId is required'));
345
+ }
346
+
347
+ const parameters = {
348
+ kmsMessage: {
349
+ method: 'delete',
350
+ uri: `${options.kmsResourceObjectUrl}/authorizations?${querystring.stringify({
351
+ authId: spaceId,
352
+ })}`,
353
+ },
354
+ };
355
+
356
+ return this.webex.internal.encryption.kms.prepareRequest(parameters.kmsMessage).then((req) => {
357
+ parameters.kmsMessage = req.wrapped;
358
+
359
+ return this.webex.request({
360
+ method: 'DELETE',
361
+ uri: `${space.url}/bindings/${options.bindingId}?${querystring.stringify(parameters)}`,
362
+ });
363
+ });
364
+ },
365
+ });
366
+
367
+ export default Space;