@cuecue/http 0.0.27 → 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 +60 -41
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var express = require('express');
|
|
6
|
+
var lodash = require('lodash');
|
|
7
|
+
var json2csv = require('json2csv');
|
|
8
|
+
var core = require('@cuecue/core');
|
|
9
|
+
var bodyParser = require('body-parser');
|
|
10
|
+
var http = require('http');
|
|
11
|
+
var cors = require('cors');
|
|
12
|
+
var createSession = require('express-session');
|
|
13
|
+
var createDebug = require('debug');
|
|
14
|
+
var axios = require('axios');
|
|
15
|
+
var StateMachine = require('javascript-state-machine');
|
|
16
|
+
var EventEmitter = require('wolfy87-eventemitter');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var express__default = /*#__PURE__*/_interopDefaultLegacy(express);
|
|
21
|
+
var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
|
|
22
|
+
var cors__default = /*#__PURE__*/_interopDefaultLegacy(cors);
|
|
23
|
+
var createSession__default = /*#__PURE__*/_interopDefaultLegacy(createSession);
|
|
24
|
+
var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
25
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
26
|
+
var StateMachine__default = /*#__PURE__*/_interopDefaultLegacy(StateMachine);
|
|
27
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
13
28
|
|
|
14
29
|
const createApi = (app, input, externalRouter = null) => {
|
|
15
|
-
const router = externalRouter === null ? new Router() : externalRouter;
|
|
30
|
+
const router = externalRouter === null ? new express.Router() : externalRouter;
|
|
16
31
|
|
|
17
32
|
const sendNotFound = res => {
|
|
18
33
|
res.status(404).json({
|
|
@@ -24,10 +39,10 @@ const createApi = (app, input, externalRouter = null) => {
|
|
|
24
39
|
const getUserId = req => req.header('X-User-Id') || null;
|
|
25
40
|
|
|
26
41
|
const downloadCSV = (res, fileName, data) => {
|
|
27
|
-
const json2csv = new Parser({
|
|
28
|
-
transforms: [transforms.flatten('.')]
|
|
42
|
+
const json2csv$1 = new json2csv.Parser({
|
|
43
|
+
transforms: [json2csv.transforms.flatten('.')]
|
|
29
44
|
});
|
|
30
|
-
const csv = json2csv.parse(data);
|
|
45
|
+
const csv = json2csv$1.parse(data);
|
|
31
46
|
res.header('Content-Type', 'text/csv');
|
|
32
47
|
res.attachment(fileName);
|
|
33
48
|
return res.send(csv);
|
|
@@ -180,7 +195,7 @@ const createApi = (app, input, externalRouter = null) => {
|
|
|
180
195
|
const format = req.params.format || null;
|
|
181
196
|
const items = await app.store.getItems('sessions', {}, true);
|
|
182
197
|
|
|
183
|
-
if (items === null || !isArray(items)) {
|
|
198
|
+
if (items === null || !lodash.isArray(items)) {
|
|
184
199
|
sendNotFound(res);
|
|
185
200
|
return;
|
|
186
201
|
}
|
|
@@ -196,7 +211,7 @@ const createApi = (app, input, externalRouter = null) => {
|
|
|
196
211
|
const format = req.params.format || null;
|
|
197
212
|
const items = await app.store.getItems('interactions', {}, true);
|
|
198
213
|
|
|
199
|
-
if (items === null || !isArray(items)) {
|
|
214
|
+
if (items === null || !lodash.isArray(items)) {
|
|
200
215
|
sendNotFound(res);
|
|
201
216
|
return;
|
|
202
217
|
}
|
|
@@ -212,7 +227,7 @@ const createApi = (app, input, externalRouter = null) => {
|
|
|
212
227
|
const format = req.params.format || null;
|
|
213
228
|
const items = await app.store.getItems('cues', {}, true);
|
|
214
229
|
|
|
215
|
-
if (items === null || !isArray(items)) {
|
|
230
|
+
if (items === null || !lodash.isArray(items)) {
|
|
216
231
|
sendNotFound(res);
|
|
217
232
|
return;
|
|
218
233
|
}
|
|
@@ -227,7 +242,7 @@ const createApi = (app, input, externalRouter = null) => {
|
|
|
227
242
|
return router;
|
|
228
243
|
};
|
|
229
244
|
|
|
230
|
-
class HttpInput extends BaseInput {
|
|
245
|
+
class HttpInput extends core.BaseInput {
|
|
231
246
|
constructor(opts = {}) {
|
|
232
247
|
super(opts);
|
|
233
248
|
this.options = {
|
|
@@ -240,8 +255,8 @@ class HttpInput extends BaseInput {
|
|
|
240
255
|
this.session = null;
|
|
241
256
|
this.http = null;
|
|
242
257
|
this.path = '/';
|
|
243
|
-
this.router = new Router();
|
|
244
|
-
this.debug =
|
|
258
|
+
this.router = new express.Router();
|
|
259
|
+
this.debug = createDebug__default["default"]('cuecue:input:http');
|
|
245
260
|
}
|
|
246
261
|
|
|
247
262
|
cue(cue, extraData = null) {
|
|
@@ -269,16 +284,16 @@ class HttpInput extends BaseInput {
|
|
|
269
284
|
const {
|
|
270
285
|
path
|
|
271
286
|
} = this.options;
|
|
272
|
-
this.express =
|
|
273
|
-
this.http = createServer(this.express);
|
|
274
|
-
this.session =
|
|
287
|
+
this.express = express__default["default"]();
|
|
288
|
+
this.http = http.createServer(this.express);
|
|
289
|
+
this.session = createSession__default["default"]({
|
|
275
290
|
secret: 'my-secret-session',
|
|
276
291
|
resave: true,
|
|
277
292
|
saveUninitialized: true
|
|
278
293
|
});
|
|
279
|
-
this.express.use(
|
|
280
|
-
this.express.use(
|
|
281
|
-
this.express.use(
|
|
294
|
+
this.express.use(cors__default["default"]());
|
|
295
|
+
this.express.use(bodyParser__default["default"].json());
|
|
296
|
+
this.express.use(bodyParser__default["default"].urlencoded({
|
|
282
297
|
extended: false
|
|
283
298
|
})); // Use express-session middleware for express
|
|
284
299
|
|
|
@@ -358,13 +373,13 @@ class ApiInput extends HttpInput {
|
|
|
358
373
|
|
|
359
374
|
}
|
|
360
375
|
|
|
361
|
-
class HttpOutput extends BaseOutput {
|
|
376
|
+
class HttpOutput extends core.BaseOutput {
|
|
362
377
|
constructor(opts = {}) {
|
|
363
378
|
super({
|
|
364
379
|
method: 'POST',
|
|
365
380
|
...opts
|
|
366
381
|
});
|
|
367
|
-
this.debug =
|
|
382
|
+
this.debug = createDebug__default["default"]('cuecue:output:http');
|
|
368
383
|
}
|
|
369
384
|
|
|
370
385
|
cue(cue, extraData = null) {
|
|
@@ -432,7 +447,7 @@ class HttpOutput extends BaseOutput {
|
|
|
432
447
|
method,
|
|
433
448
|
headers
|
|
434
449
|
} = this.options;
|
|
435
|
-
return
|
|
450
|
+
return axios__default["default"]({
|
|
436
451
|
url,
|
|
437
452
|
method,
|
|
438
453
|
headers,
|
|
@@ -442,7 +457,7 @@ class HttpOutput extends BaseOutput {
|
|
|
442
457
|
|
|
443
458
|
}
|
|
444
459
|
|
|
445
|
-
class Server extends
|
|
460
|
+
class Server extends EventEmitter__default["default"] {
|
|
446
461
|
constructor(opts = {}) {
|
|
447
462
|
super();
|
|
448
463
|
this.options = {
|
|
@@ -461,8 +476,8 @@ class Server extends EventEmitter {
|
|
|
461
476
|
this.app = null;
|
|
462
477
|
this.session = null;
|
|
463
478
|
this.http = null;
|
|
464
|
-
this.debug =
|
|
465
|
-
this.state = new
|
|
479
|
+
this.debug = createDebug__default["default"]('cuecue:server');
|
|
480
|
+
this.state = new StateMachine__default["default"]({
|
|
466
481
|
transitions: [{
|
|
467
482
|
name: 'init',
|
|
468
483
|
from: 'none',
|
|
@@ -536,16 +551,16 @@ class Server extends EventEmitter {
|
|
|
536
551
|
|
|
537
552
|
async onInit() {
|
|
538
553
|
this.emit('init');
|
|
539
|
-
this.app =
|
|
540
|
-
this.http = createServer(this.app);
|
|
541
|
-
this.session =
|
|
554
|
+
this.app = express__default["default"]();
|
|
555
|
+
this.http = http.createServer(this.app);
|
|
556
|
+
this.session = createSession__default["default"]({
|
|
542
557
|
secret: 'my-secret-session',
|
|
543
558
|
resave: true,
|
|
544
559
|
saveUninitialized: true
|
|
545
560
|
});
|
|
546
|
-
this.app.use(
|
|
547
|
-
this.app.use(
|
|
548
|
-
this.app.use(
|
|
561
|
+
this.app.use(cors__default["default"]());
|
|
562
|
+
this.app.use(bodyParser__default["default"].json());
|
|
563
|
+
this.app.use(bodyParser__default["default"].urlencoded({
|
|
549
564
|
extended: false
|
|
550
565
|
})); // Use express-session middleware for express
|
|
551
566
|
|
|
@@ -635,4 +650,8 @@ class Server extends EventEmitter {
|
|
|
635
650
|
|
|
636
651
|
}
|
|
637
652
|
|
|
638
|
-
|
|
653
|
+
exports.ApiInput = ApiInput;
|
|
654
|
+
exports.Input = HttpInput;
|
|
655
|
+
exports.Output = HttpOutput;
|
|
656
|
+
exports.Server = Server;
|
|
657
|
+
exports.createApi = createApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuecue/http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/runtime": "^7.12.5",
|
|
43
|
-
"@cuecue/core": "^0.0.
|
|
43
|
+
"@cuecue/core": "^0.0.28",
|
|
44
44
|
"axios": "^0.24.0",
|
|
45
45
|
"body-parser": "^1.19.0",
|
|
46
46
|
"commander": "^7.0.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f6865a82708bf09de192b9a6367729e9faeb1250"
|
|
60
60
|
}
|