@cuecue/http 0.0.24 → 0.0.28
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/index.js +657 -0
- package/package.json +9 -6
- package/lib/index.js +0 -1197
package/lib/index.js
DELETED
|
@@ -1,1197 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
6
|
-
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
|
-
var express = require('express');
|
|
8
|
-
var lodash = require('lodash');
|
|
9
|
-
var json2csv = require('json2csv');
|
|
10
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
11
|
-
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
12
|
-
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
13
|
-
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
14
|
-
var _createSuper = require('@babel/runtime/helpers/createSuper');
|
|
15
|
-
var core = require('@cuecue/core');
|
|
16
|
-
var bodyParser = require('body-parser');
|
|
17
|
-
var http = require('http');
|
|
18
|
-
var cors = require('cors');
|
|
19
|
-
var createSession = require('express-session');
|
|
20
|
-
var createDebug = require('debug');
|
|
21
|
-
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
|
22
|
-
var StateMachine = require('javascript-state-machine');
|
|
23
|
-
var EventEmitter = require('wolfy87-eventemitter');
|
|
24
|
-
|
|
25
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
26
|
-
|
|
27
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
28
|
-
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
29
|
-
var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
|
|
30
|
-
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
31
|
-
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
32
|
-
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
33
|
-
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
34
|
-
var _createSuper__default = /*#__PURE__*/_interopDefaultLegacy(_createSuper);
|
|
35
|
-
var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
|
|
36
|
-
var cors__default = /*#__PURE__*/_interopDefaultLegacy(cors);
|
|
37
|
-
var createSession__default = /*#__PURE__*/_interopDefaultLegacy(createSession);
|
|
38
|
-
var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
39
|
-
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
|
|
40
|
-
var StateMachine__default = /*#__PURE__*/_interopDefaultLegacy(StateMachine);
|
|
41
|
-
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
42
|
-
|
|
43
|
-
var createApi = function createApi(app, input) {
|
|
44
|
-
var externalRouter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
45
|
-
var router = externalRouter === null ? new express.Router() : externalRouter;
|
|
46
|
-
|
|
47
|
-
var sendNotFound = function sendNotFound(res) {
|
|
48
|
-
res.status(404).json({
|
|
49
|
-
success: false,
|
|
50
|
-
error: 'not_found'
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
var getUserId = function getUserId(req) {
|
|
55
|
-
return req.header('X-User-Id') || null;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
var downloadCSV = function downloadCSV(res, fileName, data) {
|
|
59
|
-
var json2csv$1 = new json2csv.Parser({
|
|
60
|
-
transforms: [json2csv.transforms.flatten('.')]
|
|
61
|
-
});
|
|
62
|
-
var csv = json2csv$1.parse(data);
|
|
63
|
-
res.header('Content-Type', 'text/csv');
|
|
64
|
-
res.attachment(fileName);
|
|
65
|
-
return res.send(csv);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
router.get('/', /*#__PURE__*/function () {
|
|
69
|
-
var _ref = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(req, res) {
|
|
70
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
71
|
-
while (1) {
|
|
72
|
-
switch (_context.prev = _context.next) {
|
|
73
|
-
case 0:
|
|
74
|
-
res.json({
|
|
75
|
-
message: 'Welcome to CueCue'
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
case 1:
|
|
79
|
-
case "end":
|
|
80
|
-
return _context.stop();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, _callee);
|
|
84
|
-
}));
|
|
85
|
-
|
|
86
|
-
return function (_x, _x2) {
|
|
87
|
-
return _ref.apply(this, arguments);
|
|
88
|
-
};
|
|
89
|
-
}());
|
|
90
|
-
router.get('/cues', /*#__PURE__*/function () {
|
|
91
|
-
var _ref2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(req, res) {
|
|
92
|
-
var cues;
|
|
93
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
|
|
94
|
-
while (1) {
|
|
95
|
-
switch (_context2.prev = _context2.next) {
|
|
96
|
-
case 0:
|
|
97
|
-
_context2.next = 2;
|
|
98
|
-
return app.getCues();
|
|
99
|
-
|
|
100
|
-
case 2:
|
|
101
|
-
cues = _context2.sent;
|
|
102
|
-
res.json(cues);
|
|
103
|
-
|
|
104
|
-
case 4:
|
|
105
|
-
case "end":
|
|
106
|
-
return _context2.stop();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}, _callee2);
|
|
110
|
-
}));
|
|
111
|
-
|
|
112
|
-
return function (_x3, _x4) {
|
|
113
|
-
return _ref2.apply(this, arguments);
|
|
114
|
-
};
|
|
115
|
-
}());
|
|
116
|
-
router.get('/cues/current', /*#__PURE__*/function () {
|
|
117
|
-
var _ref3 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(req, res) {
|
|
118
|
-
var cue;
|
|
119
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
|
|
120
|
-
while (1) {
|
|
121
|
-
switch (_context3.prev = _context3.next) {
|
|
122
|
-
case 0:
|
|
123
|
-
_context3.next = 2;
|
|
124
|
-
return app.getSessionCue();
|
|
125
|
-
|
|
126
|
-
case 2:
|
|
127
|
-
cue = _context3.sent;
|
|
128
|
-
res.json(cue);
|
|
129
|
-
|
|
130
|
-
case 4:
|
|
131
|
-
case "end":
|
|
132
|
-
return _context3.stop();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}, _callee3);
|
|
136
|
-
}));
|
|
137
|
-
|
|
138
|
-
return function (_x5, _x6) {
|
|
139
|
-
return _ref3.apply(this, arguments);
|
|
140
|
-
};
|
|
141
|
-
}());
|
|
142
|
-
router.post('/cues/define', /*#__PURE__*/function () {
|
|
143
|
-
var _ref4 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4(req, res) {
|
|
144
|
-
var _ref5, _ref5$body, body;
|
|
145
|
-
|
|
146
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
|
|
147
|
-
while (1) {
|
|
148
|
-
switch (_context4.prev = _context4.next) {
|
|
149
|
-
case 0:
|
|
150
|
-
_ref5 = req || {}, _ref5$body = _ref5.body, body = _ref5$body === void 0 ? null : _ref5$body;
|
|
151
|
-
|
|
152
|
-
if (!(body === null)) {
|
|
153
|
-
_context4.next = 4;
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
sendNotFound(res);
|
|
158
|
-
return _context4.abrupt("return");
|
|
159
|
-
|
|
160
|
-
case 4:
|
|
161
|
-
_context4.prev = 4;
|
|
162
|
-
_context4.next = 7;
|
|
163
|
-
return app.define(body);
|
|
164
|
-
|
|
165
|
-
case 7:
|
|
166
|
-
res.json({
|
|
167
|
-
success: true
|
|
168
|
-
});
|
|
169
|
-
_context4.next = 13;
|
|
170
|
-
break;
|
|
171
|
-
|
|
172
|
-
case 10:
|
|
173
|
-
_context4.prev = 10;
|
|
174
|
-
_context4.t0 = _context4["catch"](4);
|
|
175
|
-
res.json({
|
|
176
|
-
success: false
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
case 13:
|
|
180
|
-
case "end":
|
|
181
|
-
return _context4.stop();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}, _callee4, null, [[4, 10]]);
|
|
185
|
-
}));
|
|
186
|
-
|
|
187
|
-
return function (_x7, _x8) {
|
|
188
|
-
return _ref4.apply(this, arguments);
|
|
189
|
-
};
|
|
190
|
-
}());
|
|
191
|
-
router.get('/cues/:id', /*#__PURE__*/function () {
|
|
192
|
-
var _ref6 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(req, res) {
|
|
193
|
-
var cues, cue;
|
|
194
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
|
|
195
|
-
while (1) {
|
|
196
|
-
switch (_context5.prev = _context5.next) {
|
|
197
|
-
case 0:
|
|
198
|
-
_context5.next = 2;
|
|
199
|
-
return app.getCues();
|
|
200
|
-
|
|
201
|
-
case 2:
|
|
202
|
-
cues = _context5.sent;
|
|
203
|
-
cue = cues.find(function (it) {
|
|
204
|
-
return it.id === req.params.id;
|
|
205
|
-
}) || null;
|
|
206
|
-
|
|
207
|
-
if (!(cue === null)) {
|
|
208
|
-
_context5.next = 7;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
sendNotFound(res);
|
|
213
|
-
return _context5.abrupt("return");
|
|
214
|
-
|
|
215
|
-
case 7:
|
|
216
|
-
res.json(cue);
|
|
217
|
-
|
|
218
|
-
case 8:
|
|
219
|
-
case "end":
|
|
220
|
-
return _context5.stop();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}, _callee5);
|
|
224
|
-
}));
|
|
225
|
-
|
|
226
|
-
return function (_x9, _x10) {
|
|
227
|
-
return _ref6.apply(this, arguments);
|
|
228
|
-
};
|
|
229
|
-
}());
|
|
230
|
-
router.post('/cues/:id', /*#__PURE__*/function () {
|
|
231
|
-
var _ref7 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6(req, res) {
|
|
232
|
-
var cues, cue;
|
|
233
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
|
|
234
|
-
while (1) {
|
|
235
|
-
switch (_context6.prev = _context6.next) {
|
|
236
|
-
case 0:
|
|
237
|
-
_context6.next = 2;
|
|
238
|
-
return app.getCues();
|
|
239
|
-
|
|
240
|
-
case 2:
|
|
241
|
-
cues = _context6.sent;
|
|
242
|
-
cue = cues.find(function (it) {
|
|
243
|
-
return it.id === req.params.id;
|
|
244
|
-
}) || null;
|
|
245
|
-
|
|
246
|
-
if (!(cue === null)) {
|
|
247
|
-
_context6.next = 7;
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
sendNotFound(res);
|
|
252
|
-
return _context6.abrupt("return");
|
|
253
|
-
|
|
254
|
-
case 7:
|
|
255
|
-
_context6.prev = 7;
|
|
256
|
-
_context6.next = 10;
|
|
257
|
-
return input.cue(cue.id, req.body || null);
|
|
258
|
-
|
|
259
|
-
case 10:
|
|
260
|
-
res.json({
|
|
261
|
-
success: true
|
|
262
|
-
});
|
|
263
|
-
_context6.next = 16;
|
|
264
|
-
break;
|
|
265
|
-
|
|
266
|
-
case 13:
|
|
267
|
-
_context6.prev = 13;
|
|
268
|
-
_context6.t0 = _context6["catch"](7);
|
|
269
|
-
res.json({
|
|
270
|
-
success: false
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
case 16:
|
|
274
|
-
case "end":
|
|
275
|
-
return _context6.stop();
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}, _callee6, null, [[7, 13]]);
|
|
279
|
-
}));
|
|
280
|
-
|
|
281
|
-
return function (_x11, _x12) {
|
|
282
|
-
return _ref7.apply(this, arguments);
|
|
283
|
-
};
|
|
284
|
-
}());
|
|
285
|
-
router.get('/cues/:id/interactions', /*#__PURE__*/function () {
|
|
286
|
-
var _ref8 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee7(req, res) {
|
|
287
|
-
var cues, cue, interactions;
|
|
288
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee7$(_context7) {
|
|
289
|
-
while (1) {
|
|
290
|
-
switch (_context7.prev = _context7.next) {
|
|
291
|
-
case 0:
|
|
292
|
-
_context7.next = 2;
|
|
293
|
-
return app.getCues();
|
|
294
|
-
|
|
295
|
-
case 2:
|
|
296
|
-
cues = _context7.sent;
|
|
297
|
-
cue = cues.find(function (it) {
|
|
298
|
-
return it.id === req.params.id;
|
|
299
|
-
}) || null;
|
|
300
|
-
|
|
301
|
-
if (!(cue === null)) {
|
|
302
|
-
_context7.next = 7;
|
|
303
|
-
break;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
sendNotFound(res);
|
|
307
|
-
return _context7.abrupt("return");
|
|
308
|
-
|
|
309
|
-
case 7:
|
|
310
|
-
_context7.next = 9;
|
|
311
|
-
return app.getInteractionsByCue(cue.id);
|
|
312
|
-
|
|
313
|
-
case 9:
|
|
314
|
-
interactions = _context7.sent;
|
|
315
|
-
res.json(interactions);
|
|
316
|
-
|
|
317
|
-
case 11:
|
|
318
|
-
case "end":
|
|
319
|
-
return _context7.stop();
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}, _callee7);
|
|
323
|
-
}));
|
|
324
|
-
|
|
325
|
-
return function (_x13, _x14) {
|
|
326
|
-
return _ref8.apply(this, arguments);
|
|
327
|
-
};
|
|
328
|
-
}());
|
|
329
|
-
router.post('/uncue', /*#__PURE__*/function () {
|
|
330
|
-
var _ref9 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee8(req, res) {
|
|
331
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee8$(_context8) {
|
|
332
|
-
while (1) {
|
|
333
|
-
switch (_context8.prev = _context8.next) {
|
|
334
|
-
case 0:
|
|
335
|
-
_context8.prev = 0;
|
|
336
|
-
_context8.next = 3;
|
|
337
|
-
return app.uncue();
|
|
338
|
-
|
|
339
|
-
case 3:
|
|
340
|
-
res.json({
|
|
341
|
-
success: true
|
|
342
|
-
});
|
|
343
|
-
_context8.next = 9;
|
|
344
|
-
break;
|
|
345
|
-
|
|
346
|
-
case 6:
|
|
347
|
-
_context8.prev = 6;
|
|
348
|
-
_context8.t0 = _context8["catch"](0);
|
|
349
|
-
res.json({
|
|
350
|
-
success: false
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
case 9:
|
|
354
|
-
case "end":
|
|
355
|
-
return _context8.stop();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}, _callee8, null, [[0, 6]]);
|
|
359
|
-
}));
|
|
360
|
-
|
|
361
|
-
return function (_x15, _x16) {
|
|
362
|
-
return _ref9.apply(this, arguments);
|
|
363
|
-
};
|
|
364
|
-
}());
|
|
365
|
-
router.get('/interactions', /*#__PURE__*/function () {
|
|
366
|
-
var _ref10 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee9(req, res) {
|
|
367
|
-
var userId, interactions;
|
|
368
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee9$(_context9) {
|
|
369
|
-
while (1) {
|
|
370
|
-
switch (_context9.prev = _context9.next) {
|
|
371
|
-
case 0:
|
|
372
|
-
userId = getUserId(req);
|
|
373
|
-
|
|
374
|
-
if (!(userId !== null)) {
|
|
375
|
-
_context9.next = 7;
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
_context9.next = 4;
|
|
380
|
-
return app.getInteractionsByUser(userId);
|
|
381
|
-
|
|
382
|
-
case 4:
|
|
383
|
-
_context9.t0 = _context9.sent;
|
|
384
|
-
_context9.next = 10;
|
|
385
|
-
break;
|
|
386
|
-
|
|
387
|
-
case 7:
|
|
388
|
-
_context9.next = 9;
|
|
389
|
-
return app.getInteractions();
|
|
390
|
-
|
|
391
|
-
case 9:
|
|
392
|
-
_context9.t0 = _context9.sent;
|
|
393
|
-
|
|
394
|
-
case 10:
|
|
395
|
-
interactions = _context9.t0;
|
|
396
|
-
res.json(interactions);
|
|
397
|
-
|
|
398
|
-
case 12:
|
|
399
|
-
case "end":
|
|
400
|
-
return _context9.stop();
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}, _callee9);
|
|
404
|
-
}));
|
|
405
|
-
|
|
406
|
-
return function (_x17, _x18) {
|
|
407
|
-
return _ref10.apply(this, arguments);
|
|
408
|
-
};
|
|
409
|
-
}());
|
|
410
|
-
router.post('/interactions', /*#__PURE__*/function () {
|
|
411
|
-
var _ref11 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee10(req, res) {
|
|
412
|
-
var userId;
|
|
413
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee10$(_context10) {
|
|
414
|
-
while (1) {
|
|
415
|
-
switch (_context10.prev = _context10.next) {
|
|
416
|
-
case 0:
|
|
417
|
-
_context10.prev = 0;
|
|
418
|
-
userId = getUserId(req);
|
|
419
|
-
_context10.next = 4;
|
|
420
|
-
return input.interact(req.body, userId);
|
|
421
|
-
|
|
422
|
-
case 4:
|
|
423
|
-
res.json({
|
|
424
|
-
success: true
|
|
425
|
-
});
|
|
426
|
-
_context10.next = 10;
|
|
427
|
-
break;
|
|
428
|
-
|
|
429
|
-
case 7:
|
|
430
|
-
_context10.prev = 7;
|
|
431
|
-
_context10.t0 = _context10["catch"](0);
|
|
432
|
-
res.json({
|
|
433
|
-
success: false
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
case 10:
|
|
437
|
-
case "end":
|
|
438
|
-
return _context10.stop();
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}, _callee10, null, [[0, 7]]);
|
|
442
|
-
}));
|
|
443
|
-
|
|
444
|
-
return function (_x19, _x20) {
|
|
445
|
-
return _ref11.apply(this, arguments);
|
|
446
|
-
};
|
|
447
|
-
}());
|
|
448
|
-
router.get('/session/current', /*#__PURE__*/function () {
|
|
449
|
-
var _ref12 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee11(req, res) {
|
|
450
|
-
var session;
|
|
451
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee11$(_context11) {
|
|
452
|
-
while (1) {
|
|
453
|
-
switch (_context11.prev = _context11.next) {
|
|
454
|
-
case 0:
|
|
455
|
-
session = app.session;
|
|
456
|
-
|
|
457
|
-
if (!(session === null)) {
|
|
458
|
-
_context11.next = 4;
|
|
459
|
-
break;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
sendNotFound(res);
|
|
463
|
-
return _context11.abrupt("return");
|
|
464
|
-
|
|
465
|
-
case 4:
|
|
466
|
-
res.json(session.id);
|
|
467
|
-
|
|
468
|
-
case 5:
|
|
469
|
-
case "end":
|
|
470
|
-
return _context11.stop();
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}, _callee11);
|
|
474
|
-
}));
|
|
475
|
-
|
|
476
|
-
return function (_x21, _x22) {
|
|
477
|
-
return _ref12.apply(this, arguments);
|
|
478
|
-
};
|
|
479
|
-
}());
|
|
480
|
-
router.get('/session/:id', /*#__PURE__*/function () {
|
|
481
|
-
var _ref13 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee12(req, res) {
|
|
482
|
-
var session;
|
|
483
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee12$(_context12) {
|
|
484
|
-
while (1) {
|
|
485
|
-
switch (_context12.prev = _context12.next) {
|
|
486
|
-
case 0:
|
|
487
|
-
session = app.session; // TODO: Find a session?
|
|
488
|
-
|
|
489
|
-
if (!(session === null)) {
|
|
490
|
-
_context12.next = 4;
|
|
491
|
-
break;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
sendNotFound(res);
|
|
495
|
-
return _context12.abrupt("return");
|
|
496
|
-
|
|
497
|
-
case 4:
|
|
498
|
-
res.json(session);
|
|
499
|
-
|
|
500
|
-
case 5:
|
|
501
|
-
case "end":
|
|
502
|
-
return _context12.stop();
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}, _callee12);
|
|
506
|
-
}));
|
|
507
|
-
|
|
508
|
-
return function (_x23, _x24) {
|
|
509
|
-
return _ref13.apply(this, arguments);
|
|
510
|
-
};
|
|
511
|
-
}());
|
|
512
|
-
router.get('/app/state', /*#__PURE__*/function () {
|
|
513
|
-
var _ref14 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee13(req, res) {
|
|
514
|
-
var state;
|
|
515
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee13$(_context13) {
|
|
516
|
-
while (1) {
|
|
517
|
-
switch (_context13.prev = _context13.next) {
|
|
518
|
-
case 0:
|
|
519
|
-
state = app.state.state;
|
|
520
|
-
|
|
521
|
-
if (!(state === null)) {
|
|
522
|
-
_context13.next = 4;
|
|
523
|
-
break;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
sendNotFound(res);
|
|
527
|
-
return _context13.abrupt("return");
|
|
528
|
-
|
|
529
|
-
case 4:
|
|
530
|
-
res.json(state);
|
|
531
|
-
|
|
532
|
-
case 5:
|
|
533
|
-
case "end":
|
|
534
|
-
return _context13.stop();
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}, _callee13);
|
|
538
|
-
}));
|
|
539
|
-
|
|
540
|
-
return function (_x25, _x26) {
|
|
541
|
-
return _ref14.apply(this, arguments);
|
|
542
|
-
};
|
|
543
|
-
}());
|
|
544
|
-
router.get('/export/sessions.:format', /*#__PURE__*/function () {
|
|
545
|
-
var _ref15 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(req, res) {
|
|
546
|
-
var format, items;
|
|
547
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
|
|
548
|
-
while (1) {
|
|
549
|
-
switch (_context14.prev = _context14.next) {
|
|
550
|
-
case 0:
|
|
551
|
-
format = req.params.format || null;
|
|
552
|
-
_context14.next = 3;
|
|
553
|
-
return app.store.getItems('sessions', {}, true);
|
|
554
|
-
|
|
555
|
-
case 3:
|
|
556
|
-
items = _context14.sent;
|
|
557
|
-
|
|
558
|
-
if (!(items === null || !lodash.isArray(items))) {
|
|
559
|
-
_context14.next = 7;
|
|
560
|
-
break;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
sendNotFound(res);
|
|
564
|
-
return _context14.abrupt("return");
|
|
565
|
-
|
|
566
|
-
case 7:
|
|
567
|
-
if (!(format === 'csv')) {
|
|
568
|
-
_context14.next = 10;
|
|
569
|
-
break;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
downloadCSV(res, 'sessions.csv', items);
|
|
573
|
-
return _context14.abrupt("return");
|
|
574
|
-
|
|
575
|
-
case 10:
|
|
576
|
-
res.json(items);
|
|
577
|
-
|
|
578
|
-
case 11:
|
|
579
|
-
case "end":
|
|
580
|
-
return _context14.stop();
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}, _callee14);
|
|
584
|
-
}));
|
|
585
|
-
|
|
586
|
-
return function (_x27, _x28) {
|
|
587
|
-
return _ref15.apply(this, arguments);
|
|
588
|
-
};
|
|
589
|
-
}());
|
|
590
|
-
router.get('/export/interactions.:format', /*#__PURE__*/function () {
|
|
591
|
-
var _ref16 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee15(req, res) {
|
|
592
|
-
var format, items;
|
|
593
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee15$(_context15) {
|
|
594
|
-
while (1) {
|
|
595
|
-
switch (_context15.prev = _context15.next) {
|
|
596
|
-
case 0:
|
|
597
|
-
format = req.params.format || null;
|
|
598
|
-
_context15.next = 3;
|
|
599
|
-
return app.store.getItems('interactions', {}, true);
|
|
600
|
-
|
|
601
|
-
case 3:
|
|
602
|
-
items = _context15.sent;
|
|
603
|
-
|
|
604
|
-
if (!(items === null || !lodash.isArray(items))) {
|
|
605
|
-
_context15.next = 7;
|
|
606
|
-
break;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
sendNotFound(res);
|
|
610
|
-
return _context15.abrupt("return");
|
|
611
|
-
|
|
612
|
-
case 7:
|
|
613
|
-
if (!(format === 'csv')) {
|
|
614
|
-
_context15.next = 10;
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
downloadCSV(res, 'interactions.csv', items);
|
|
619
|
-
return _context15.abrupt("return");
|
|
620
|
-
|
|
621
|
-
case 10:
|
|
622
|
-
res.json(items);
|
|
623
|
-
|
|
624
|
-
case 11:
|
|
625
|
-
case "end":
|
|
626
|
-
return _context15.stop();
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}, _callee15);
|
|
630
|
-
}));
|
|
631
|
-
|
|
632
|
-
return function (_x29, _x30) {
|
|
633
|
-
return _ref16.apply(this, arguments);
|
|
634
|
-
};
|
|
635
|
-
}());
|
|
636
|
-
router.get('/export/cues.:format', /*#__PURE__*/function () {
|
|
637
|
-
var _ref17 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee16(req, res) {
|
|
638
|
-
var format, items;
|
|
639
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee16$(_context16) {
|
|
640
|
-
while (1) {
|
|
641
|
-
switch (_context16.prev = _context16.next) {
|
|
642
|
-
case 0:
|
|
643
|
-
format = req.params.format || null;
|
|
644
|
-
_context16.next = 3;
|
|
645
|
-
return app.store.getItems('cues', {}, true);
|
|
646
|
-
|
|
647
|
-
case 3:
|
|
648
|
-
items = _context16.sent;
|
|
649
|
-
|
|
650
|
-
if (!(items === null || !lodash.isArray(items))) {
|
|
651
|
-
_context16.next = 7;
|
|
652
|
-
break;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
sendNotFound(res);
|
|
656
|
-
return _context16.abrupt("return");
|
|
657
|
-
|
|
658
|
-
case 7:
|
|
659
|
-
if (!(format === 'csv')) {
|
|
660
|
-
_context16.next = 10;
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
downloadCSV(res, 'cues.csv', items);
|
|
665
|
-
return _context16.abrupt("return");
|
|
666
|
-
|
|
667
|
-
case 10:
|
|
668
|
-
res.json(items);
|
|
669
|
-
|
|
670
|
-
case 11:
|
|
671
|
-
case "end":
|
|
672
|
-
return _context16.stop();
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}, _callee16);
|
|
676
|
-
}));
|
|
677
|
-
|
|
678
|
-
return function (_x31, _x32) {
|
|
679
|
-
return _ref17.apply(this, arguments);
|
|
680
|
-
};
|
|
681
|
-
}());
|
|
682
|
-
return router;
|
|
683
|
-
};
|
|
684
|
-
|
|
685
|
-
var HttpInput = /*#__PURE__*/function (_BaseInput) {
|
|
686
|
-
_inherits__default['default'](HttpInput, _BaseInput);
|
|
687
|
-
|
|
688
|
-
var _super = _createSuper__default['default'](HttpInput);
|
|
689
|
-
|
|
690
|
-
function HttpInput() {
|
|
691
|
-
var _this;
|
|
692
|
-
|
|
693
|
-
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
694
|
-
|
|
695
|
-
_classCallCheck__default['default'](this, HttpInput);
|
|
696
|
-
|
|
697
|
-
_this = _super.call(this, opts);
|
|
698
|
-
_this.options = _objectSpread__default['default']({
|
|
699
|
-
port: process.env.PORT || 8080,
|
|
700
|
-
publicPath: null,
|
|
701
|
-
path: process.env.ROUTER_PATH || '/api'
|
|
702
|
-
}, opts);
|
|
703
|
-
_this.express = null;
|
|
704
|
-
_this.session = null;
|
|
705
|
-
_this.http = null;
|
|
706
|
-
_this.path = '/';
|
|
707
|
-
_this.router = new express.Router();
|
|
708
|
-
_this.debug = createDebug__default['default']('cuecue:input:http');
|
|
709
|
-
return _this;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
_createClass__default['default'](HttpInput, [{
|
|
713
|
-
key: "cue",
|
|
714
|
-
value: function cue(_cue) {
|
|
715
|
-
var extraData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
716
|
-
this.emit('command', 'cue', _cue, extraData);
|
|
717
|
-
}
|
|
718
|
-
}, {
|
|
719
|
-
key: "interact",
|
|
720
|
-
value: function interact(data) {
|
|
721
|
-
var interactionId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
722
|
-
this.emit('command', 'interact', data, interactionId);
|
|
723
|
-
}
|
|
724
|
-
}, {
|
|
725
|
-
key: "getRouter",
|
|
726
|
-
value: function getRouter() {
|
|
727
|
-
return this.router;
|
|
728
|
-
}
|
|
729
|
-
}, {
|
|
730
|
-
key: "setRouter",
|
|
731
|
-
value: function setRouter(router) {
|
|
732
|
-
this.router = router;
|
|
733
|
-
}
|
|
734
|
-
}, {
|
|
735
|
-
key: "use",
|
|
736
|
-
value: function use() {
|
|
737
|
-
var _this$express;
|
|
738
|
-
|
|
739
|
-
return (_this$express = this.express).use.apply(_this$express, arguments);
|
|
740
|
-
}
|
|
741
|
-
}, {
|
|
742
|
-
key: "onInit",
|
|
743
|
-
value: function () {
|
|
744
|
-
var _onInit = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
|
|
745
|
-
var path;
|
|
746
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
747
|
-
while (1) {
|
|
748
|
-
switch (_context.prev = _context.next) {
|
|
749
|
-
case 0:
|
|
750
|
-
this.emit('init');
|
|
751
|
-
path = this.options.path;
|
|
752
|
-
this.express = express__default['default']();
|
|
753
|
-
this.http = http.createServer(this.express);
|
|
754
|
-
this.session = createSession__default['default']({
|
|
755
|
-
secret: 'my-secret-session',
|
|
756
|
-
resave: true,
|
|
757
|
-
saveUninitialized: true
|
|
758
|
-
});
|
|
759
|
-
this.express.use(cors__default['default']());
|
|
760
|
-
this.express.use(bodyParser__default['default'].json());
|
|
761
|
-
this.express.use(bodyParser__default['default'].urlencoded({
|
|
762
|
-
extended: false
|
|
763
|
-
})); // Use express-session middleware for express
|
|
764
|
-
|
|
765
|
-
this.express.use(this.session);
|
|
766
|
-
|
|
767
|
-
if (this.router !== null) {
|
|
768
|
-
this.use(path, this.router);
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
_context.next = 12;
|
|
772
|
-
return this.startServer();
|
|
773
|
-
|
|
774
|
-
case 12:
|
|
775
|
-
case "end":
|
|
776
|
-
return _context.stop();
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
}, _callee, this);
|
|
780
|
-
}));
|
|
781
|
-
|
|
782
|
-
function onInit() {
|
|
783
|
-
return _onInit.apply(this, arguments);
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
return onInit;
|
|
787
|
-
}()
|
|
788
|
-
}, {
|
|
789
|
-
key: "onDestroy",
|
|
790
|
-
value: function () {
|
|
791
|
-
var _onDestroy = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
|
|
792
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
|
|
793
|
-
while (1) {
|
|
794
|
-
switch (_context2.prev = _context2.next) {
|
|
795
|
-
case 0:
|
|
796
|
-
this.debug('destroying...');
|
|
797
|
-
this.emit('destroy');
|
|
798
|
-
_context2.prev = 2;
|
|
799
|
-
_context2.next = 5;
|
|
800
|
-
return this.stopServer();
|
|
801
|
-
|
|
802
|
-
case 5:
|
|
803
|
-
_context2.next = 10;
|
|
804
|
-
break;
|
|
805
|
-
|
|
806
|
-
case 7:
|
|
807
|
-
_context2.prev = 7;
|
|
808
|
-
_context2.t0 = _context2["catch"](2);
|
|
809
|
-
this.debug('destroy error %O', _context2.t0);
|
|
810
|
-
|
|
811
|
-
case 10:
|
|
812
|
-
this.express = null;
|
|
813
|
-
this.http = null;
|
|
814
|
-
this.session = null;
|
|
815
|
-
|
|
816
|
-
case 13:
|
|
817
|
-
case "end":
|
|
818
|
-
return _context2.stop();
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
}, _callee2, this, [[2, 7]]);
|
|
822
|
-
}));
|
|
823
|
-
|
|
824
|
-
function onDestroy() {
|
|
825
|
-
return _onDestroy.apply(this, arguments);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
return onDestroy;
|
|
829
|
-
}()
|
|
830
|
-
}, {
|
|
831
|
-
key: "onStarted",
|
|
832
|
-
value: function onStarted() {
|
|
833
|
-
var _this2 = this;
|
|
834
|
-
|
|
835
|
-
var port = this.options.port;
|
|
836
|
-
this.debug("started on *:".concat(port));
|
|
837
|
-
return process.nextTick(function () {
|
|
838
|
-
return _this2.emit('started');
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
}, {
|
|
842
|
-
key: "startServer",
|
|
843
|
-
value: function startServer() {
|
|
844
|
-
var _this3 = this;
|
|
845
|
-
|
|
846
|
-
var port = this.options.port;
|
|
847
|
-
return new Promise(function (resolve, reject) {
|
|
848
|
-
_this3.http.listen(port, function (err) {
|
|
849
|
-
if (err) {
|
|
850
|
-
reject(err);
|
|
851
|
-
return;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
resolve();
|
|
855
|
-
});
|
|
856
|
-
});
|
|
857
|
-
}
|
|
858
|
-
}, {
|
|
859
|
-
key: "stopServer",
|
|
860
|
-
value: function stopServer() {
|
|
861
|
-
var _this4 = this;
|
|
862
|
-
|
|
863
|
-
this.debug('Stopping...');
|
|
864
|
-
return new Promise(function (resolve, reject) {
|
|
865
|
-
_this4.http.close(function (err) {
|
|
866
|
-
if (err) {
|
|
867
|
-
reject(err);
|
|
868
|
-
return;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
resolve();
|
|
872
|
-
});
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
}]);
|
|
876
|
-
|
|
877
|
-
return HttpInput;
|
|
878
|
-
}(core.BaseInput);
|
|
879
|
-
|
|
880
|
-
var Server = /*#__PURE__*/function (_EventEmitter) {
|
|
881
|
-
_inherits__default['default'](Server, _EventEmitter);
|
|
882
|
-
|
|
883
|
-
var _super = _createSuper__default['default'](Server);
|
|
884
|
-
|
|
885
|
-
function Server() {
|
|
886
|
-
var _this;
|
|
887
|
-
|
|
888
|
-
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
889
|
-
|
|
890
|
-
_classCallCheck__default['default'](this, Server);
|
|
891
|
-
|
|
892
|
-
_this = _super.call(this);
|
|
893
|
-
_this.options = _objectSpread__default['default']({
|
|
894
|
-
port: process.env.PORT || 8080,
|
|
895
|
-
publicPath: null
|
|
896
|
-
}, opts);
|
|
897
|
-
_this.onInit = _this.onInit.bind(_assertThisInitialized__default['default'](_this));
|
|
898
|
-
_this.onInitialized = _this.onInitialized.bind(_assertThisInitialized__default['default'](_this));
|
|
899
|
-
_this.onDestroy = _this.onDestroy.bind(_assertThisInitialized__default['default'](_this));
|
|
900
|
-
_this.onDestroyed = _this.onDestroyed.bind(_assertThisInitialized__default['default'](_this));
|
|
901
|
-
_this.onStart = _this.onStart.bind(_assertThisInitialized__default['default'](_this));
|
|
902
|
-
_this.onStop = _this.onStop.bind(_assertThisInitialized__default['default'](_this));
|
|
903
|
-
_this.onStarted = _this.onStarted.bind(_assertThisInitialized__default['default'](_this));
|
|
904
|
-
_this.onStopped = _this.onStopped.bind(_assertThisInitialized__default['default'](_this));
|
|
905
|
-
_this.app = null;
|
|
906
|
-
_this.session = null;
|
|
907
|
-
_this.http = null;
|
|
908
|
-
_this.debug = createDebug__default['default']('cuecue:server');
|
|
909
|
-
_this.state = new StateMachine__default['default']({
|
|
910
|
-
transitions: [{
|
|
911
|
-
name: 'init',
|
|
912
|
-
from: 'none',
|
|
913
|
-
to: 'initialized'
|
|
914
|
-
}, {
|
|
915
|
-
name: 'destroy',
|
|
916
|
-
from: '*',
|
|
917
|
-
to: 'none'
|
|
918
|
-
}, {
|
|
919
|
-
name: 'start',
|
|
920
|
-
from: ['initialized', 'stopped'],
|
|
921
|
-
to: 'started'
|
|
922
|
-
}, {
|
|
923
|
-
name: 'stop',
|
|
924
|
-
from: 'started',
|
|
925
|
-
to: 'stopped'
|
|
926
|
-
}],
|
|
927
|
-
methods: {
|
|
928
|
-
onBeforeInit: _this.onInit,
|
|
929
|
-
onAfterInit: _this.onInitialized,
|
|
930
|
-
onBeforeDestroy: _this.onDestroy,
|
|
931
|
-
onAfterDestroy: _this.onDestroyed,
|
|
932
|
-
onBeforeStart: _this.onStart,
|
|
933
|
-
onAfterStart: _this.onStarted,
|
|
934
|
-
onBeforeStop: _this.onStop,
|
|
935
|
-
onAfterStop: _this.onStopped
|
|
936
|
-
}
|
|
937
|
-
});
|
|
938
|
-
|
|
939
|
-
_this.init();
|
|
940
|
-
|
|
941
|
-
return _this;
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
_createClass__default['default'](Server, [{
|
|
945
|
-
key: "init",
|
|
946
|
-
value: function init() {
|
|
947
|
-
return this.state.init();
|
|
948
|
-
}
|
|
949
|
-
}, {
|
|
950
|
-
key: "destroy",
|
|
951
|
-
value: function destroy() {
|
|
952
|
-
return this.state.destroy();
|
|
953
|
-
}
|
|
954
|
-
}, {
|
|
955
|
-
key: "start",
|
|
956
|
-
value: function () {
|
|
957
|
-
var _start = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
|
|
958
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
959
|
-
while (1) {
|
|
960
|
-
switch (_context.prev = _context.next) {
|
|
961
|
-
case 0:
|
|
962
|
-
if (this.initialized()) {
|
|
963
|
-
_context.next = 3;
|
|
964
|
-
break;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
_context.next = 3;
|
|
968
|
-
return this.init();
|
|
969
|
-
|
|
970
|
-
case 3:
|
|
971
|
-
return _context.abrupt("return", this.state.start());
|
|
972
|
-
|
|
973
|
-
case 4:
|
|
974
|
-
case "end":
|
|
975
|
-
return _context.stop();
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
}, _callee, this);
|
|
979
|
-
}));
|
|
980
|
-
|
|
981
|
-
function start() {
|
|
982
|
-
return _start.apply(this, arguments);
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
return start;
|
|
986
|
-
}()
|
|
987
|
-
}, {
|
|
988
|
-
key: "stop",
|
|
989
|
-
value: function stop() {
|
|
990
|
-
return this.state.stop();
|
|
991
|
-
}
|
|
992
|
-
}, {
|
|
993
|
-
key: "initialized",
|
|
994
|
-
value: function initialized() {
|
|
995
|
-
return this.state.is('initialized');
|
|
996
|
-
}
|
|
997
|
-
}, {
|
|
998
|
-
key: "started",
|
|
999
|
-
value: function started() {
|
|
1000
|
-
return this.state.is('started');
|
|
1001
|
-
}
|
|
1002
|
-
}, {
|
|
1003
|
-
key: "stopped",
|
|
1004
|
-
value: function stopped() {
|
|
1005
|
-
return this.state.is('stopped');
|
|
1006
|
-
}
|
|
1007
|
-
}, {
|
|
1008
|
-
key: "destroyed",
|
|
1009
|
-
value: function destroyed() {
|
|
1010
|
-
return this.state.is('destroyed');
|
|
1011
|
-
}
|
|
1012
|
-
}, {
|
|
1013
|
-
key: "use",
|
|
1014
|
-
value: function use() {
|
|
1015
|
-
var _this$app;
|
|
1016
|
-
|
|
1017
|
-
return (_this$app = this.app).use.apply(_this$app, arguments);
|
|
1018
|
-
}
|
|
1019
|
-
}, {
|
|
1020
|
-
key: "onInit",
|
|
1021
|
-
value: function () {
|
|
1022
|
-
var _onInit = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
|
|
1023
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
|
|
1024
|
-
while (1) {
|
|
1025
|
-
switch (_context2.prev = _context2.next) {
|
|
1026
|
-
case 0:
|
|
1027
|
-
this.emit('init');
|
|
1028
|
-
this.app = express__default['default']();
|
|
1029
|
-
this.http = http.createServer(this.app);
|
|
1030
|
-
this.session = createSession__default['default']({
|
|
1031
|
-
secret: 'my-secret-session',
|
|
1032
|
-
resave: true,
|
|
1033
|
-
saveUninitialized: true
|
|
1034
|
-
});
|
|
1035
|
-
this.app.use(cors__default['default']());
|
|
1036
|
-
this.app.use(bodyParser__default['default'].json());
|
|
1037
|
-
this.app.use(bodyParser__default['default'].urlencoded({
|
|
1038
|
-
extended: false
|
|
1039
|
-
})); // Use express-session middleware for express
|
|
1040
|
-
|
|
1041
|
-
this.app.use(this.session);
|
|
1042
|
-
_context2.next = 10;
|
|
1043
|
-
return this.startServer();
|
|
1044
|
-
|
|
1045
|
-
case 10:
|
|
1046
|
-
case "end":
|
|
1047
|
-
return _context2.stop();
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
}, _callee2, this);
|
|
1051
|
-
}));
|
|
1052
|
-
|
|
1053
|
-
function onInit() {
|
|
1054
|
-
return _onInit.apply(this, arguments);
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
return onInit;
|
|
1058
|
-
}()
|
|
1059
|
-
}, {
|
|
1060
|
-
key: "onInitialized",
|
|
1061
|
-
value: function onInitialized() {
|
|
1062
|
-
var _this2 = this;
|
|
1063
|
-
|
|
1064
|
-
this.debug('initialized');
|
|
1065
|
-
return process.nextTick(function () {
|
|
1066
|
-
return _this2.emit('initialized');
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
}, {
|
|
1070
|
-
key: "onDestroy",
|
|
1071
|
-
value: function () {
|
|
1072
|
-
var _onDestroy = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3() {
|
|
1073
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
|
|
1074
|
-
while (1) {
|
|
1075
|
-
switch (_context3.prev = _context3.next) {
|
|
1076
|
-
case 0:
|
|
1077
|
-
this.debug('destroying...');
|
|
1078
|
-
this.emit('destroy');
|
|
1079
|
-
_context3.prev = 2;
|
|
1080
|
-
_context3.next = 5;
|
|
1081
|
-
return this.stopServer();
|
|
1082
|
-
|
|
1083
|
-
case 5:
|
|
1084
|
-
if (this.session !== null && typeof this.session.close !== 'undefined') {
|
|
1085
|
-
this.session.close();
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
_context3.next = 11;
|
|
1089
|
-
break;
|
|
1090
|
-
|
|
1091
|
-
case 8:
|
|
1092
|
-
_context3.prev = 8;
|
|
1093
|
-
_context3.t0 = _context3["catch"](2);
|
|
1094
|
-
this.debug('onDestroy error %O', _context3.t0);
|
|
1095
|
-
|
|
1096
|
-
case 11:
|
|
1097
|
-
this.app = null;
|
|
1098
|
-
this.http = null;
|
|
1099
|
-
|
|
1100
|
-
case 13:
|
|
1101
|
-
case "end":
|
|
1102
|
-
return _context3.stop();
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
}, _callee3, this, [[2, 8]]);
|
|
1106
|
-
}));
|
|
1107
|
-
|
|
1108
|
-
function onDestroy() {
|
|
1109
|
-
return _onDestroy.apply(this, arguments);
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
return onDestroy;
|
|
1113
|
-
}()
|
|
1114
|
-
}, {
|
|
1115
|
-
key: "onDestroyed",
|
|
1116
|
-
value: function onDestroyed() {
|
|
1117
|
-
var _this3 = this;
|
|
1118
|
-
|
|
1119
|
-
this.debug('destroyed');
|
|
1120
|
-
return process.nextTick(function () {
|
|
1121
|
-
return _this3.emit('destroyed');
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
}, {
|
|
1125
|
-
key: "onStart",
|
|
1126
|
-
value: function onStart() {
|
|
1127
|
-
this.debug('starting...');
|
|
1128
|
-
this.emit('start');
|
|
1129
|
-
}
|
|
1130
|
-
}, {
|
|
1131
|
-
key: "onStarted",
|
|
1132
|
-
value: function onStarted() {
|
|
1133
|
-
var _this4 = this;
|
|
1134
|
-
|
|
1135
|
-
var port = this.options.port;
|
|
1136
|
-
this.debug("started on *:".concat(port));
|
|
1137
|
-
return process.nextTick(function () {
|
|
1138
|
-
return _this4.emit('started');
|
|
1139
|
-
});
|
|
1140
|
-
}
|
|
1141
|
-
}, {
|
|
1142
|
-
key: "onStop",
|
|
1143
|
-
value: function onStop() {
|
|
1144
|
-
this.emit('stop');
|
|
1145
|
-
}
|
|
1146
|
-
}, {
|
|
1147
|
-
key: "onStopped",
|
|
1148
|
-
value: function onStopped() {
|
|
1149
|
-
var _this5 = this;
|
|
1150
|
-
|
|
1151
|
-
this.debug('Stopped.');
|
|
1152
|
-
return process.nextTick(function () {
|
|
1153
|
-
return _this5.emit('stopped');
|
|
1154
|
-
});
|
|
1155
|
-
}
|
|
1156
|
-
}, {
|
|
1157
|
-
key: "startServer",
|
|
1158
|
-
value: function startServer() {
|
|
1159
|
-
var _this6 = this;
|
|
1160
|
-
|
|
1161
|
-
var port = this.options.port;
|
|
1162
|
-
return new Promise(function (resolve, reject) {
|
|
1163
|
-
_this6.http.listen(port, function (err) {
|
|
1164
|
-
if (err) {
|
|
1165
|
-
reject(err);
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
resolve();
|
|
1170
|
-
});
|
|
1171
|
-
});
|
|
1172
|
-
}
|
|
1173
|
-
}, {
|
|
1174
|
-
key: "stopServer",
|
|
1175
|
-
value: function stopServer() {
|
|
1176
|
-
var _this7 = this;
|
|
1177
|
-
|
|
1178
|
-
this.debug('Stopping...');
|
|
1179
|
-
return new Promise(function (resolve, reject) {
|
|
1180
|
-
_this7.http.close(function (err) {
|
|
1181
|
-
if (err) {
|
|
1182
|
-
reject(err);
|
|
1183
|
-
return;
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
|
-
resolve();
|
|
1187
|
-
});
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
|
-
}]);
|
|
1191
|
-
|
|
1192
|
-
return Server;
|
|
1193
|
-
}(EventEmitter__default['default']);
|
|
1194
|
-
|
|
1195
|
-
exports.Input = HttpInput;
|
|
1196
|
-
exports.Server = Server;
|
|
1197
|
-
exports.createApi = createApi;
|