@webex/webex-server 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/session.js CHANGED
@@ -1,249 +1,249 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import fs from 'fs';
6
- import util from 'util';
7
-
8
- import bodyParser from 'body-parser';
9
- import express from 'express';
10
- import validator from 'express-validator';
11
- import session from 'express-session';
12
- import {get} from 'lodash';
13
-
14
- import WebexCore from './webex';
15
- import MemoryStore from './memory-store';
16
-
17
- /* eslint-disable camelcase */
18
- /* eslint-disable no-console */
19
- // express induces more callbacks than usual
20
- /* eslint-disable max-nested-callbacks */
21
-
22
- // eslint-disable-next-line
23
- const router = express.Router();
24
-
25
- export default router;
26
-
27
- router.use(bodyParser.json());
28
- router.use(validator());
29
- router.use(
30
- session({
31
- resave: true,
32
- saveUninitialized: true,
33
- secret: 'keyboardcat',
34
- store: new MemoryStore(),
35
- })
36
- );
37
-
38
- /**
39
- * Return the details for a given session
40
- * @type {Function}
41
- */
42
- router.get('/session', (req, res) => {
43
- const {webex} = req.session;
44
-
45
- if (!webex) {
46
- res.status(404).end();
47
-
48
- return;
49
- }
50
-
51
- res
52
- .status(200)
53
- .send({
54
- webex: webex.serialize(),
55
- })
56
- .end();
57
- });
58
-
59
- /**
60
- * Initialize a webex instance, connect it to mercury, and set a session cookie.
61
- * @type {Function}
62
- */
63
- router.put('/session', (req, res, next) => {
64
- req.checkBody('clientId').notEmpty();
65
- req.checkBody('clientSecret').notEmpty();
66
- req.checkBody('redirectUri').notEmpty();
67
- req.checkBody('scope').notEmpty();
68
- req.checkBody('user').notEmpty();
69
- req.checkBody('user.token').notEmpty();
70
- req.checkBody('user.token.access_token').notEmpty();
71
- req.checkBody('user.token.token_type').notEmpty();
72
- req.checkBody('user.token.expires_in').notEmpty();
73
-
74
- req.getValidationResult().then((result) => {
75
- if (!result.isEmpty()) {
76
- console.info(result.array());
77
- res.status(400).send(`${result.array()[0].param} is missing`);
78
-
79
- return;
80
- }
81
- const webex = new WebexCore({
82
- credentials: req.body.user.token,
83
- config: {
84
- credentials: {
85
- client_id: req.body.clientId,
86
- client_secret: req.body.clientSecret,
87
- redirect_uri: req.body.redirectUri,
88
- scope: req.body.scope,
89
- },
90
- },
91
- });
92
-
93
- req.session.webex = webex;
94
-
95
- webex.internal.mercury
96
- .connect()
97
- .then(() => res.status(200).send({webex}).end())
98
- .catch((err) => {
99
- console.error(err);
100
- next(err);
101
- });
102
- });
103
- });
104
-
105
- /**
106
- * Disconnect a webex instance and unregister its device
107
- */
108
- router.delete('/session', (req, res, next) => {
109
- const {webex} = req.session;
110
-
111
- if (!webex) {
112
- res
113
- .status(404)
114
- .send({
115
- err: 'no webex instance found for session',
116
- })
117
- .end();
118
-
119
- return;
120
- }
121
-
122
- webex.internal.mercury
123
- .disconnect()
124
- .then(() => {
125
- req.session.destroy((err) => {
126
- if (err) {
127
- next(err);
128
-
129
- return;
130
- }
131
-
132
- res.status(204).end();
133
- });
134
- })
135
- .catch((err) => {
136
- req.session.destroy((err2) => {
137
- if (err2) {
138
- next(err2);
139
-
140
- return;
141
- }
142
- next(err);
143
- });
144
- });
145
- });
146
-
147
- router.post('/session/invoke/internal/conversation/share', (req, res) => {
148
- console.info('invoke conversation share called');
149
- const {webex} = req.session;
150
-
151
- if (!webex) {
152
- console.info('invoke: No session found - did you forget to hit /session?');
153
- res
154
- .status(404)
155
- .send({
156
- message: 'No session found - did you forget to hit /session?',
157
- })
158
- .end();
159
-
160
- return;
161
- }
162
-
163
- const share = webex.internal.conversation.makeShare(req.body[0]);
164
-
165
- req.body[1].files.forEach((fileJson) => {
166
- const file = fs.readFileSync(fileJson.path); // eslint-disable-line no-sync
167
-
168
- file.name = fileJson.displayName;
169
- share.add(file);
170
- });
171
-
172
- console.info('invoke: invoking "conversation.share" with arguments\n', util.inspect(req.body));
173
- webex.internal.conversation
174
- .share(req.body[0], share)
175
- .then((result) => {
176
- res.status(200).send(result).end();
177
- })
178
- .catch((reason) => {
179
- console.log(reason);
180
- res
181
- .status(400)
182
- .send({
183
- message: 'An error occured while processing your request',
184
- error: reason.toString(),
185
- upstreamStatusCode: reason.statusCode,
186
- upstreamResponse: reason.body,
187
- })
188
- .end();
189
- });
190
- });
191
-
192
- /**
193
- * Invoke an sdk method.
194
- */
195
- router.post(/^\/session\/invoke\/.*/, (req, res) => {
196
- console.info('invoke called');
197
- const {webex} = req.session;
198
-
199
- if (!webex) {
200
- console.info('invoke: No session found - did you forget to hit /session?');
201
- res
202
- .status(404)
203
- .send({
204
- message: 'No session found - did you forget to hit /session?',
205
- })
206
- .end();
207
-
208
- return;
209
- }
210
-
211
- const invokePath = req.url.substr(req.url.indexOf('invoke') + 7);
212
- const keypath = invokePath.split('/');
213
-
214
- const method = get(webex, keypath.join('.'));
215
-
216
- console.info(111, method, keypath);
217
- const methodName = keypath.pop();
218
-
219
- console.info(222, methodName);
220
-
221
- let context = get(webex, keypath.join('.'));
222
-
223
- if (!context) {
224
- context = webex;
225
- }
226
-
227
- console.info(333, context);
228
-
229
- const label = `webex.${keypath.join('.')}.${methodName}()`;
230
-
231
- console.info(`invoke: invoking "${label}" with arguments\n`, util.inspect(req.body));
232
- Reflect.apply(method, context, req.body)
233
- .then((result) => {
234
- console.info(`invoke: successfully invoked "${label}"`);
235
- res.status(200).send(result).end();
236
- })
237
- .catch((reason) => {
238
- console.error({req, err: reason}, `invoke: "${label}" failed with error`);
239
- res
240
- .status(502)
241
- .send({
242
- message: 'An error occured while processing your request',
243
- error: reason.toString(),
244
- upstreamStatusCode: reason.statusCode,
245
- upstreamResponse: reason.body,
246
- })
247
- .end();
248
- });
249
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import fs from 'fs';
6
+ import util from 'util';
7
+
8
+ import bodyParser from 'body-parser';
9
+ import express from 'express';
10
+ import validator from 'express-validator';
11
+ import session from 'express-session';
12
+ import {get} from 'lodash';
13
+
14
+ import WebexCore from './webex';
15
+ import MemoryStore from './memory-store';
16
+
17
+ /* eslint-disable camelcase */
18
+ /* eslint-disable no-console */
19
+ // express induces more callbacks than usual
20
+ /* eslint-disable max-nested-callbacks */
21
+
22
+ // eslint-disable-next-line
23
+ const router = express.Router();
24
+
25
+ export default router;
26
+
27
+ router.use(bodyParser.json());
28
+ router.use(validator());
29
+ router.use(
30
+ session({
31
+ resave: true,
32
+ saveUninitialized: true,
33
+ secret: 'keyboardcat',
34
+ store: new MemoryStore(),
35
+ })
36
+ );
37
+
38
+ /**
39
+ * Return the details for a given session
40
+ * @type {Function}
41
+ */
42
+ router.get('/session', (req, res) => {
43
+ const {webex} = req.session;
44
+
45
+ if (!webex) {
46
+ res.status(404).end();
47
+
48
+ return;
49
+ }
50
+
51
+ res
52
+ .status(200)
53
+ .send({
54
+ webex: webex.serialize(),
55
+ })
56
+ .end();
57
+ });
58
+
59
+ /**
60
+ * Initialize a webex instance, connect it to mercury, and set a session cookie.
61
+ * @type {Function}
62
+ */
63
+ router.put('/session', (req, res, next) => {
64
+ req.checkBody('clientId').notEmpty();
65
+ req.checkBody('clientSecret').notEmpty();
66
+ req.checkBody('redirectUri').notEmpty();
67
+ req.checkBody('scope').notEmpty();
68
+ req.checkBody('user').notEmpty();
69
+ req.checkBody('user.token').notEmpty();
70
+ req.checkBody('user.token.access_token').notEmpty();
71
+ req.checkBody('user.token.token_type').notEmpty();
72
+ req.checkBody('user.token.expires_in').notEmpty();
73
+
74
+ req.getValidationResult().then((result) => {
75
+ if (!result.isEmpty()) {
76
+ console.info(result.array());
77
+ res.status(400).send(`${result.array()[0].param} is missing`);
78
+
79
+ return;
80
+ }
81
+ const webex = new WebexCore({
82
+ credentials: req.body.user.token,
83
+ config: {
84
+ credentials: {
85
+ client_id: req.body.clientId,
86
+ client_secret: req.body.clientSecret,
87
+ redirect_uri: req.body.redirectUri,
88
+ scope: req.body.scope,
89
+ },
90
+ },
91
+ });
92
+
93
+ req.session.webex = webex;
94
+
95
+ webex.internal.mercury
96
+ .connect()
97
+ .then(() => res.status(200).send({webex}).end())
98
+ .catch((err) => {
99
+ console.error(err);
100
+ next(err);
101
+ });
102
+ });
103
+ });
104
+
105
+ /**
106
+ * Disconnect a webex instance and unregister its device
107
+ */
108
+ router.delete('/session', (req, res, next) => {
109
+ const {webex} = req.session;
110
+
111
+ if (!webex) {
112
+ res
113
+ .status(404)
114
+ .send({
115
+ err: 'no webex instance found for session',
116
+ })
117
+ .end();
118
+
119
+ return;
120
+ }
121
+
122
+ webex.internal.mercury
123
+ .disconnect()
124
+ .then(() => {
125
+ req.session.destroy((err) => {
126
+ if (err) {
127
+ next(err);
128
+
129
+ return;
130
+ }
131
+
132
+ res.status(204).end();
133
+ });
134
+ })
135
+ .catch((err) => {
136
+ req.session.destroy((err2) => {
137
+ if (err2) {
138
+ next(err2);
139
+
140
+ return;
141
+ }
142
+ next(err);
143
+ });
144
+ });
145
+ });
146
+
147
+ router.post('/session/invoke/internal/conversation/share', (req, res) => {
148
+ console.info('invoke conversation share called');
149
+ const {webex} = req.session;
150
+
151
+ if (!webex) {
152
+ console.info('invoke: No session found - did you forget to hit /session?');
153
+ res
154
+ .status(404)
155
+ .send({
156
+ message: 'No session found - did you forget to hit /session?',
157
+ })
158
+ .end();
159
+
160
+ return;
161
+ }
162
+
163
+ const share = webex.internal.conversation.makeShare(req.body[0]);
164
+
165
+ req.body[1].files.forEach((fileJson) => {
166
+ const file = fs.readFileSync(fileJson.path); // eslint-disable-line no-sync
167
+
168
+ file.name = fileJson.displayName;
169
+ share.add(file);
170
+ });
171
+
172
+ console.info('invoke: invoking "conversation.share" with arguments\n', util.inspect(req.body));
173
+ webex.internal.conversation
174
+ .share(req.body[0], share)
175
+ .then((result) => {
176
+ res.status(200).send(result).end();
177
+ })
178
+ .catch((reason) => {
179
+ console.log(reason);
180
+ res
181
+ .status(400)
182
+ .send({
183
+ message: 'An error occured while processing your request',
184
+ error: reason.toString(),
185
+ upstreamStatusCode: reason.statusCode,
186
+ upstreamResponse: reason.body,
187
+ })
188
+ .end();
189
+ });
190
+ });
191
+
192
+ /**
193
+ * Invoke an sdk method.
194
+ */
195
+ router.post(/^\/session\/invoke\/.*/, (req, res) => {
196
+ console.info('invoke called');
197
+ const {webex} = req.session;
198
+
199
+ if (!webex) {
200
+ console.info('invoke: No session found - did you forget to hit /session?');
201
+ res
202
+ .status(404)
203
+ .send({
204
+ message: 'No session found - did you forget to hit /session?',
205
+ })
206
+ .end();
207
+
208
+ return;
209
+ }
210
+
211
+ const invokePath = req.url.substr(req.url.indexOf('invoke') + 7);
212
+ const keypath = invokePath.split('/');
213
+
214
+ const method = get(webex, keypath.join('.'));
215
+
216
+ console.info(111, method, keypath);
217
+ const methodName = keypath.pop();
218
+
219
+ console.info(222, methodName);
220
+
221
+ let context = get(webex, keypath.join('.'));
222
+
223
+ if (!context) {
224
+ context = webex;
225
+ }
226
+
227
+ console.info(333, context);
228
+
229
+ const label = `webex.${keypath.join('.')}.${methodName}()`;
230
+
231
+ console.info(`invoke: invoking "${label}" with arguments\n`, util.inspect(req.body));
232
+ Reflect.apply(method, context, req.body)
233
+ .then((result) => {
234
+ console.info(`invoke: successfully invoked "${label}"`);
235
+ res.status(200).send(result).end();
236
+ })
237
+ .catch((reason) => {
238
+ console.error({req, err: reason}, `invoke: "${label}" failed with error`);
239
+ res
240
+ .status(502)
241
+ .send({
242
+ message: 'An error occured while processing your request',
243
+ error: reason.toString(),
244
+ upstreamStatusCode: reason.statusCode,
245
+ upstreamResponse: reason.body,
246
+ })
247
+ .end();
248
+ });
249
+ });
package/src/webex.js CHANGED
@@ -1,26 +1,26 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import '@babel/polyfill';
6
-
7
- import '@webex/plugin-authorization-node';
8
- import '@webex/internal-plugin-avatar';
9
- import '@webex/internal-plugin-board';
10
- import '@webex/internal-plugin-calendar';
11
- import '@webex/internal-plugin-conversation';
12
- import '@webex/internal-plugin-encryption';
13
- import '@webex/internal-plugin-feature';
14
- import '@webex/internal-plugin-flag';
15
- import '@webex/plugin-logger';
16
- import '@webex/internal-plugin-mercury';
17
- import '@webex/internal-plugin-metrics';
18
- import '@webex/internal-plugin-search';
19
- import '@webex/internal-plugin-support';
20
- import '@webex/internal-plugin-team';
21
- import '@webex/internal-plugin-user';
22
- import '@webex/internal-plugin-device';
23
-
24
- import WebexCore from '@webex/webex-core';
25
-
26
- export default WebexCore;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@babel/polyfill';
6
+
7
+ import '@webex/plugin-authorization-node';
8
+ import '@webex/internal-plugin-avatar';
9
+ import '@webex/internal-plugin-board';
10
+ import '@webex/internal-plugin-calendar';
11
+ import '@webex/internal-plugin-conversation';
12
+ import '@webex/internal-plugin-encryption';
13
+ import '@webex/internal-plugin-feature';
14
+ import '@webex/internal-plugin-flag';
15
+ import '@webex/plugin-logger';
16
+ import '@webex/internal-plugin-mercury';
17
+ import '@webex/internal-plugin-metrics';
18
+ import '@webex/internal-plugin-search';
19
+ import '@webex/internal-plugin-support';
20
+ import '@webex/internal-plugin-team';
21
+ import '@webex/internal-plugin-user';
22
+ import '@webex/internal-plugin-device';
23
+
24
+ import WebexCore from '@webex/webex-core';
25
+
26
+ export default WebexCore;