total5 0.0.2 → 0.0.3-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/changelog.txt CHANGED
@@ -1,3 +1,13 @@
1
+ ========================
2
+ 0.0.3
3
+ ========================
4
+
5
+ - extended icon validator by adding support for `tic` keyword
6
+ - added new events `ON('request')`, `ON('controller')` and `ON('websocket')`
7
+ - fixed applying the `$insecure` option in the FlowStream
8
+ - fixed routing for unexpected content-type
9
+ - added `controller.authorize([callback])` method
10
+
1
11
  ========================
2
12
  0.0.2
3
13
  ========================
package/controller.js CHANGED
@@ -188,6 +188,10 @@ Controller.prototype.callback = function(err, value) {
188
188
 
189
189
  };
190
190
 
191
+ Controller.prototype.cancel = function() {
192
+ this.iscanceled = true;
193
+ };
194
+
191
195
  Controller.prototype.csrf = function() {
192
196
  return F.def.onCSRFcreate(this);
193
197
  };
@@ -881,6 +885,7 @@ Controller.prototype.hostname = function(path) {
881
885
  Controller.prototype.$route = function() {
882
886
 
883
887
  var ctrl = this;
888
+
884
889
  if (ctrl.isfile) {
885
890
 
886
891
  if (F.routes.files.length) {
@@ -943,7 +948,6 @@ Controller.prototype.$route = function() {
943
948
 
944
949
  ctrl.payload = Buffer.concat(ctrl.payload);
945
950
  F.stats.performance.download += ctrl.payload.length / 1024 / 1024;
946
-
947
951
  switch (ctrl.datatype) {
948
952
  case 'json':
949
953
  ctrl.body = F.def.parsers.json(ctrl.payload.toString('utf8'));
@@ -987,6 +991,29 @@ function readfile(filename, callback) {
987
991
  });
988
992
  }
989
993
 
994
+ /*
995
+ @Path: Controller
996
+ @Method: instance.authorize([callback]); #callback {Function(err, session)} optional;
997
+ The method performs "manual" authorization. If the user is logged in, then `session {Object}` is not null, otherwise `null`. If you don't use the `callback` argument, then the method returns `Promise`.
998
+ */
999
+ Controller.prototype.authorize = function(callback) {
1000
+
1001
+ var ctrl = this;
1002
+
1003
+ if (!callback)
1004
+ return new Promise((resolve, reject) => ctrl.authorize((err, response) => resolve(response)));
1005
+
1006
+ if (F.def.onAuthorize) {
1007
+ var opt = new F.TBuilders.Options(ctrl);
1008
+ opt.TYPE = 'auth';
1009
+ opt.query = ctrl.query;
1010
+ opt.next = opt.callback;
1011
+ opt.$callback = (err, response) => callback(null, response);
1012
+ F.def.onAuthorize(opt);
1013
+ } else
1014
+ callback();
1015
+ }
1016
+
990
1017
  Controller.prototype.notmodified = function(date) {
991
1018
  var ctrl = this;
992
1019
  if (ctrl.headers['if-modified-since'] === date) {
@@ -1137,6 +1164,7 @@ function execute(ctrl, skipmiddleware) {
1137
1164
 
1138
1165
  let schema = body.schema.split('/');
1139
1166
  let endpoint = ctrl.route.api[schema[0]];
1167
+
1140
1168
  if (endpoint) {
1141
1169
 
1142
1170
  if ((endpoint.auth === 1 && ctrl.user == null) || (endpoint.auth === 2 && ctrl.user)) {
@@ -1170,29 +1198,56 @@ function execute(ctrl, skipmiddleware) {
1170
1198
 
1171
1199
  ctrl.params = params;
1172
1200
  ctrl.query = query ? query.parseEncoded() : {};
1201
+
1202
+ if (body)
1203
+ ctrl.body = body;
1204
+
1205
+ if (F.$events.controller) {
1206
+ F.emit('controller', ctrl);
1207
+ if (ctrl.iscanceled)
1208
+ return;
1209
+ }
1210
+
1173
1211
  let action = endpoint.action;
1174
- if (action) {
1175
- ctrl.body = body || {};
1212
+ if (action)
1176
1213
  action(ctrl);
1177
- } else
1178
- F.action(endpoint.actions, body || {}, ctrl).autorespond();
1214
+ else
1215
+ F.action(endpoint.actions, ctrl.body, ctrl).autorespond();
1216
+
1179
1217
  return;
1180
1218
  }
1181
1219
  }
1182
1220
 
1183
- ctrl.fallback(400, 'Invalid data');
1184
1221
  }
1222
+
1223
+ ctrl.fallback(400, 'Invalid data');
1224
+
1185
1225
  } else {
1226
+
1227
+ if (F.$events.controller) {
1228
+ /*
1229
+ @Path: Framework
1230
+ @Event: ON('controller', function(ctrl) { ... }); #ctrl {Controller};
1231
+ The event captures all processed controllers on HTTP requests. The next processing can be canceled via the `ctrl.cancel()` method.
1232
+ */
1233
+ F.emit('controller', ctrl);
1234
+ if (ctrl.iscanceled)
1235
+ return;
1236
+ }
1237
+
1186
1238
  if (ctrl.route.actions) {
1187
1239
  F.action(ctrl.route.actions, ctrl.body, ctrl).autorespond();
1188
1240
  } else {
1241
+
1189
1242
  if (ctrl.route.view) {
1190
1243
  ctrl.view(ctrl.route.view);
1191
1244
  return;
1192
1245
  }
1246
+
1193
1247
  let action = ctrl.route.action;
1194
1248
  if (!action)
1195
1249
  action = auto_view;
1250
+
1196
1251
  action(ctrl);
1197
1252
  }
1198
1253
  }
@@ -1467,6 +1467,9 @@ function init_worker(meta, type, callback) {
1467
1467
 
1468
1468
  var forkargs = [F.directory, '--fork'];
1469
1469
 
1470
+ if (F.config.$insecure)
1471
+ forkargs.push('--insecure');
1472
+
1470
1473
  if (meta.memory)
1471
1474
  forkargs.push('--max-old-space-size=' + meta.memory);
1472
1475
 
@@ -3323,7 +3326,12 @@ function makeunixsocket(id) {
3323
3326
 
3324
3327
  if (process.argv[1].endsWith('flow-flowstream.js')) {
3325
3328
 
3326
- isFLOWSTREAMWORKER = W.workerData || process.argv.indexOf('--fork') !== -1;
3329
+ isFLOWSTREAMWORKER = W.workerData || process.argv.includes('--fork');
3330
+
3331
+ if (process.argv.includes('--insecure')) {
3332
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1';
3333
+ F.config.$insecure = true;
3334
+ }
3327
3335
 
3328
3336
  // Runs the worker
3329
3337
  if (W.workerData) {
package/http.js CHANGED
@@ -65,6 +65,19 @@ exports.listen = function(req, res) {
65
65
  // Pending requests
66
66
  F.temporary.pending.push(ctrl);
67
67
 
68
+ if (F.$events.request) {
69
+
70
+ /*
71
+ @Path: Framework
72
+ @Event: ON('request', function(ctrl) { ... }); #ctrl {Controller};
73
+ The event captures all incoming requests. The next processing can be canceled via the `ctrl.cancel()` method.
74
+ */
75
+ F.emit('request', ctrl);
76
+
77
+ if (ctrl.iscanceled)
78
+ return;
79
+ }
80
+
68
81
  if (ctrl.headers.origin && (F.def.onCORS || F.config.$cors)) {
69
82
  if (F.TRouting.lookupcors(ctrl))
70
83
  ctrl.$route();
package/index.js CHANGED
@@ -36,7 +36,7 @@ global.DEF = {};
36
36
 
37
37
  F.id = '';
38
38
  F.clusterid = '';
39
- F.is5 = F.version = 5000;
39
+ F.is5 = F.version = 5003;
40
40
  F.isBundle = false;
41
41
  F.isLoaded = false;
42
42
  F.version_header = '5';
package/jsonschema.js CHANGED
@@ -8,7 +8,7 @@ require('./index');
8
8
 
9
9
  const REG_NUMBER = /[\d,.]+/;
10
10
  const REG_COLOR = /^#([A-F0-9]{3}|[A-F0-9]{6}|[A-F0-9]{8})$/i;
11
- const REG_ICON = /^(ti|far|fab|fad|fal|fas|fa)?\s(fa|ti)-[a-z0-9-]+$/;
11
+ const REG_ICON = /^(ti|tic|far|fab|fad|fal|fas|fa)?\s(fa|ti|tic)-[a-z0-9-]+$/;
12
12
  const REG_WSPACE = /\u00A0/g;
13
13
 
14
14
  function Value() {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "total5",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-1",
4
4
  "description": "Total.js framework v5",
5
5
  "main": "index.js",
6
6
  "directories": {
package/tms.js CHANGED
@@ -101,7 +101,7 @@ function tmscontroller($) {
101
101
  }
102
102
  } else {
103
103
  msg.error = true;
104
- msg.data = new ErrorBuilder.push(404).output();
104
+ msg.data = new ErrorBuilder().push(404).output();
105
105
  client.send(msg);
106
106
  }
107
107
  }
@@ -377,4 +377,4 @@ F.on('$tms', function() {
377
377
  Cache.socket && Cache.socket.close(1000, 'Changed TMS secret');
378
378
  }
379
379
 
380
- });
380
+ });
package/websocket.js CHANGED
@@ -110,7 +110,19 @@ Controller.prototype.upgrade = function(websocket) {
110
110
  ctrl.socket.on('end', websocket_close);
111
111
  ctrl.parent.add(ctrl);
112
112
  websocket.online++;
113
- F.$events.websocket_begin && F.emit('websocket_begin', ctrl.parent, ctrl);
113
+
114
+ // Deprecated:
115
+ // F.$events.websocket_begin && F.emit('websocket_begin', ctrl.parent, ctrl);
116
+
117
+ if (F.$events.websocket) {
118
+ /*
119
+ @Path: Framework
120
+ @Event: ON('websocket', function(ctrl) { ... }); #ctrl {Controller};
121
+ The event captures all incoming WebSocket connections. The next processing __can't be__ canceled via the `ctrl.cancel()` method.
122
+ */
123
+ F.emit('websocket', ctrl);
124
+ }
125
+
114
126
  ctrl.parent.$events.open && ctrl.parent.emit('open', ctrl);
115
127
  };
116
128