miolo 0.0.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.
Files changed (70) hide show
  1. package/.babelrc.js +12 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +50 -0
  4. package/lib/cacher/index.js +98 -0
  5. package/lib/cacher/verify.js +32 -0
  6. package/lib/config/defaults.js +204 -0
  7. package/lib/config/index.js +14 -0
  8. package/lib/db/conn.js +15 -0
  9. package/lib/emailer/index.js +62 -0
  10. package/lib/emailer/verify.js +13 -0
  11. package/lib/index.js +59 -0
  12. package/lib/logger/index.js +98 -0
  13. package/lib/logger/logger_mail.js +59 -0
  14. package/lib/logger/verify.js +25 -0
  15. package/lib/server/engines/cron/index.js +16 -0
  16. package/lib/server/engines/cron/syscheck.js +50 -0
  17. package/lib/server/engines/socket/index.js +48 -0
  18. package/lib/server/index.js +126 -0
  19. package/lib/server/middleware/_cors.js +130 -0
  20. package/lib/server/middleware/auth/basic.js +72 -0
  21. package/lib/server/middleware/auth/passport.js +119 -0
  22. package/lib/server/middleware/body.js +48 -0
  23. package/lib/server/middleware/catcher.js +54 -0
  24. package/lib/server/middleware/request.js +56 -0
  25. package/lib/server/middleware/session/index.js +24 -0
  26. package/lib/server/middleware/session/store.js +5 -0
  27. package/lib/server/middleware/static.js +34 -0
  28. package/lib/server/routes/catch_js_error.js +42 -0
  29. package/lib/server/routes/crud.js +32 -0
  30. package/lib/server/routes/fallback_index.html +24 -0
  31. package/lib/server/routes/html_render.js +48 -0
  32. package/lib/server/routes/queries.js +45 -0
  33. package/lib/server/routes/robots.js +37 -0
  34. package/lib/server/static/img/favicon.ico +0 -0
  35. package/lib/server/static/robots.txt +2 -0
  36. package/package.json +49 -0
  37. package/src/cacher/index.js +61 -0
  38. package/src/cacher/verify.js +20 -0
  39. package/src/config/defaults.js +204 -0
  40. package/src/config/index.js +11 -0
  41. package/src/db/conn.js +10 -0
  42. package/src/emailer/index.js +64 -0
  43. package/src/emailer/verify.js +8 -0
  44. package/src/index.js +16 -0
  45. package/src/logger/index.js +95 -0
  46. package/src/logger/logger_mail.js +70 -0
  47. package/src/logger/verify.js +22 -0
  48. package/src/server/engines/cron/index.js +18 -0
  49. package/src/server/engines/cron/syscheck.js +50 -0
  50. package/src/server/engines/socket/index.js +38 -0
  51. package/src/server/index.js +95 -0
  52. package/src/server/middleware/_cors.js +130 -0
  53. package/src/server/middleware/auth/basic.js +57 -0
  54. package/src/server/middleware/auth/passport.js +111 -0
  55. package/src/server/middleware/body.js +45 -0
  56. package/src/server/middleware/catcher.js +44 -0
  57. package/src/server/middleware/request.js +46 -0
  58. package/src/server/middleware/session/index.js +16 -0
  59. package/src/server/middleware/session/store.js +3 -0
  60. package/src/server/middleware/static.js +19 -0
  61. package/src/server/routes/catch_js_error.js +28 -0
  62. package/src/server/routes/crud.js +14 -0
  63. package/src/server/routes/fallback_index.html +24 -0
  64. package/src/server/routes/html_render.js +33 -0
  65. package/src/server/routes/queries.js +26 -0
  66. package/src/server/routes/robots.js +20 -0
  67. package/src/server/static/img/favicon.ico +0 -0
  68. package/src/server/static/robots.txt +2 -0
  69. package/start.sh +3 -0
  70. package/stop.sh +3 -0
package/.babelrc.js ADDED
@@ -0,0 +1,12 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ presets: [
5
+ ["@babel/preset-env", {"targets": {"esmodules": true}}]
6
+ ],
7
+ plugins: [
8
+ [require.resolve('babel-plugin-module-resolver'), {
9
+ "root": [path.resolve('./')]
10
+ }]
11
+ ]
12
+ }
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ **/build
2
+ **/dist
3
+ **/lib
package/.eslintrc.js ADDED
@@ -0,0 +1,50 @@
1
+ module.exports = {
2
+ "root": true,
3
+ "parser": "@babel/eslint-parser",
4
+ "extends": ["eslint:recommended"],
5
+ "parserOptions": {
6
+ "ecmaVersion": 7,
7
+ "sourceType": "module",
8
+ "ecmaFeatures": {
9
+ "globalReturn ": true,
10
+ "impliedStrict": true,
11
+ "experimentalObjectRestSpread": true
12
+ }
13
+ },
14
+ "env": {
15
+ "browser": true,
16
+ "mocha": true,
17
+ "node": true,
18
+ "es6": true
19
+ },
20
+ "rules": {
21
+ "semi": 0,
22
+ "vars-on-top": 0,
23
+ "spaced-comment": 0,
24
+ "prefer-template": 0,
25
+ "consistent-return": 0,
26
+ "comma-dangle": 0,
27
+ "no-use-before-define": 0,
28
+ "no-return-assign": 0,
29
+ "no-case-declarations": 0,
30
+ "no-cond-assign": 0,
31
+ "no-console": 0,
32
+ "max-len": 0,
33
+ "arrow-body-style": 0,
34
+ "new-cap": 0,
35
+ "quotes": 0,
36
+ "quote-props": 0,
37
+ "prefer-arrow-callback": 0,
38
+ "func-names": 0,
39
+ "padded-blocks": 0,
40
+ "keyword-spacing": 0,
41
+ "no-var": 1,
42
+ "no-trailing-spaces": 0,
43
+ "no-unused-expressions": 0,
44
+ "no-unused-vars": [1, {"argsIgnorePattern": "^_", "varsIgnorePattern": "^_"}],
45
+ "no-inner-declarations": 0,
46
+ "space-before-function-paren": 0,
47
+ "global-require": 0,
48
+ "no-empty": 0
49
+ }
50
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.init_cacher = init_cacher;
7
+
8
+ var _redis = _interopRequireDefault(require("redis"));
9
+
10
+ var _util = require("util");
11
+
12
+ var _farrapaColors = require("farrapa-colors");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
+
18
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
19
+
20
+ function init_cacher(config) {
21
+ var client = _redis.default.createClient(config.redis.port, config.redis.host).on('connect', function () {
22
+ console.info("".concat((0, _farrapaColors.PURPLE)('REDIS'), " Connection established!"));
23
+ }).on('error', function (err) {
24
+ var msg;
25
+
26
+ try {
27
+ if (err instanceof _redis.default.ReplyError) msg = "".concat((0, _farrapaColors.PURPLE)('REDIS'), " ").concat((0, _farrapaColors.RED)('Error ' + err.code), " Command: ").concat(err.command, " ").concat(err.toString());else msg = "".concat((0, _farrapaColors.PURPLE)('REDIS'), " ").concat((0, _farrapaColors.RED)('Error ' + err.code), " ").concat(err.toString());
28
+ } catch (e) {
29
+ msg = "".concat((0, _farrapaColors.PURPLE)('REDIS'), " ").concat((0, _farrapaColors.RED)('Error '), " ").concat(e);
30
+ }
31
+
32
+ console.error(msg);
33
+ });
34
+
35
+ var _getKey = (0, _util.promisify)(client.get).bind(client);
36
+
37
+ var _existsKey = (0, _util.promisify)(client.exists).bind(client);
38
+
39
+ var _setKey = (0, _util.promisify)(client.set).bind(client);
40
+
41
+ var _delKey = (0, _util.promisify)(client.del).bind(client);
42
+
43
+ function redisGet(_x) {
44
+ return _redisGet.apply(this, arguments);
45
+ }
46
+
47
+ function _redisGet() {
48
+ _redisGet = _asyncToGenerator(function* (key) {
49
+ return yield _getKey(key);
50
+ });
51
+ return _redisGet.apply(this, arguments);
52
+ }
53
+
54
+ function redisExists(_x2) {
55
+ return _redisExists.apply(this, arguments);
56
+ }
57
+
58
+ function _redisExists() {
59
+ _redisExists = _asyncToGenerator(function* (key) {
60
+ var r = yield _existsKey(key);
61
+ return r == 1 ? true : false;
62
+ });
63
+ return _redisExists.apply(this, arguments);
64
+ }
65
+
66
+ function redisSet(_x3, _x4) {
67
+ return _redisSet.apply(this, arguments);
68
+ }
69
+
70
+ function _redisSet() {
71
+ _redisSet = _asyncToGenerator(function* (key, value) {
72
+ var expiration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 86400;
73
+ var r = yield _setKey(key, value, 'EX', expiration);
74
+ return r == 'OK' ? true : false;
75
+ });
76
+ return _redisSet.apply(this, arguments);
77
+ }
78
+
79
+ function redisDel(_x5) {
80
+ return _redisDel.apply(this, arguments);
81
+ }
82
+
83
+ function _redisDel() {
84
+ _redisDel = _asyncToGenerator(function* (key) {
85
+ var r = yield _delKey(key);
86
+ return r >= 1 ? true : false;
87
+ });
88
+ return _redisDel.apply(this, arguments);
89
+ }
90
+
91
+ var cacher = {
92
+ get: redisGet,
93
+ exists: redisExists,
94
+ set: redisSet,
95
+ del: redisDel
96
+ };
97
+ return cacher;
98
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.verify_cacher = verify_cacher;
7
+
8
+ var _index = require("./index");
9
+
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
11
+
12
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
+
14
+ function verify_cacher(_x) {
15
+ return _verify_cacher.apply(this, arguments);
16
+ }
17
+
18
+ function _verify_cacher() {
19
+ _verify_cacher = _asyncToGenerator(function* (config) {
20
+ var cacher = (0, _index.make_cacher)(config);
21
+ var rs = yield cacher.set('test', 'I will be expired in 10 seconds', 10);
22
+ if (!rs) console.warning('[miolo][Verify][REDIS] Verifying error: Redis could not be tested (S)!');else {
23
+ var rd = yield cacher.del('test');
24
+ if (!rd) console.warning('[miolo][Verify][REDIS] Verifying error: Redis could not be tested (D)!');else {
25
+ console.info('[miolo][Verify][REDIS] Verifying: Redis Tested OK');
26
+ return true;
27
+ }
28
+ }
29
+ return false;
30
+ });
31
+ return _verify_cacher.apply(this, arguments);
32
+ }
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+
3
+ var path = require('path');
4
+
5
+ var favicon = path.resolve(__dirname, '../server/static/ig/favicon.ico');
6
+ module.exports = {
7
+ name: 'miolo',
8
+ http: {
9
+ port: 8001,
10
+ hostname: 'localhost',
11
+ static: {
12
+ favicon: favicon,
13
+ folders: {}
14
+ }
15
+ },
16
+ session: {
17
+ salt: 'SUPER_SALTY_YES?',
18
+ secret: 'SUPER_SECRET_KEY_KERE',
19
+ expires: 9 * 3600 * 1000 // 9 hours
20
+
21
+ },
22
+ database: {
23
+ connection: {
24
+ dialect: 'postgres',
25
+ host: 'localhost',
26
+ port: 5432,
27
+ database: 'miolo',
28
+ user: 'postgres',
29
+ password: 'postgres',
30
+ max: 5,
31
+ // Maximum number of connection in pool
32
+ min: 0,
33
+ // Minimum number of connection in pool
34
+ idleTimeoutMillis: 10000 // The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
35
+
36
+ },
37
+ options: {
38
+ log: 'debug'
39
+ }
40
+ },
41
+ routes: {// crud: {
42
+ // path: '/crud',
43
+ // routes: [
44
+ // {
45
+ // name: 'todos',
46
+ // options: {
47
+ // useDates: true,
48
+ // checkBeforeDelete: ["edition.agent_id"],
49
+ // customHooks: {
50
+ // beforeInsert: beforeInsertTest,
51
+ // beforeUpdate: beforeUpdateTest
52
+ // }
53
+ // }
54
+ // }
55
+ // ],
56
+ // },
57
+ // queries: [
58
+ // {
59
+ // path: '/crud/fo/bar',
60
+ // method: 'GET',
61
+ // callback: method_receiving_params_ctx_conn
62
+ // }
63
+ // ]
64
+ },
65
+ cacher: {
66
+ redis: {
67
+ host: '127.0.0.1',
68
+ port: 6379
69
+ }
70
+ },
71
+ log: {
72
+ level: 'debug',
73
+ format: {
74
+ locale: 'en-GB'
75
+ },
76
+ console: {
77
+ enabled: true,
78
+ level: 'silly'
79
+ },
80
+ file: {
81
+ enabled: true,
82
+ level: 'silly',
83
+ filename: '/var/log/afialapis/miolo.log'
84
+ },
85
+ mail: {
86
+ enabled: process.env.NODE_ENV === 'production',
87
+ level: 'warn'
88
+ }
89
+ },
90
+ mail: {
91
+ silent: process.env.NODE_ENV !== 'production',
92
+ options: {
93
+ //
94
+ // General options
95
+ //
96
+ // port – is the port to connect to (defaults to 587 is secure is false or 465 if true)
97
+ port: 25,
98
+ // host – is the hostname or IP address to connect to (defaults to ‘localhost’)
99
+ host: 'mail.afialapis.com',
100
+ // auth – defines authentication data
101
+ // If authentication data is not present, the connection is considered authenticated from the start.
102
+ // Otherwise you would need to provide the authentication options object.
103
+ // - type indicates the authetication type, defaults to ‘login’, other option is ‘oauth2’
104
+ // - user is the username
105
+ // - pass is the password for the user if normal login is used
106
+ // authMethod – defines preferred authentication method, defaults to ‘PLAIN’
107
+ authMethod: 'PLAIN',
108
+ //
109
+ // TLS options
110
+ //
111
+ // secure – if true the connection will use TLS when connecting to server.
112
+ // If false (the default) then TLS is used if server supports the STARTTLS extension.
113
+ // In most cases set this value to true if you are connecting to port 465. For port 587 or 25 keep it false
114
+ // ** Setting secure to false does not mean that you would not use an encrypted connection. Most SMTP servers allow
115
+ // connection upgrade via STARTTLS command but to use this you have to connect using plaintext first
116
+ secure: false,
117
+ // tls – defines additional node.js TLSSocket options to be passed to the socket constructor, eg. {rejectUnauthorized: true}.
118
+ tls: {
119
+ // do not fail on invalid certs
120
+ rejectUnauthorized: false
121
+ },
122
+ // ignoreTLS – if this is true and secure is false then TLS is not used even if the server supports STARTTLS extension
123
+ // ** ignoreTLS: false,
124
+ // requireTLS – if this is true and secure is false then Nodemailer tries to use STARTTLS even
125
+ // if the server does not advertise support for it. If the connection can not be encrypted then message is not sent
126
+ // ** requireTLS: true,
127
+ //
128
+ // Connection options
129
+ //
130
+ // name – optional hostname of the client, used for identifying to the server, defaults to hostname of the machine
131
+ // ** name: ,
132
+ // localAddress – is the local interface to bind to for network connections
133
+ // ** localAddress: ,
134
+ // connectionTimeout – how many milliseconds to wait for the connection to establish
135
+ // ** connectionTimeout: ,
136
+ // greetingTimeout – how many milliseconds to wait for the greeting after connection is established
137
+ // ** greetingTimeout: ,
138
+ // socketTimeout – how many milliseconds of inactivity to allow
139
+ // ** socketTimeout: ,
140
+ //
141
+ // Debug options
142
+ //
143
+ // logger – optional bunyan compatible logger instance. If set to true then logs to console.
144
+ // If value is not set or is false then nothing is logged
145
+ logger: false,
146
+ // debug – if set to true, then logs SMTP traffic, otherwise logs only transaction events
147
+ debug: false //
148
+ // Security options
149
+ //
150
+ // disableFileAccess – if true, then does not allow to use files as content.
151
+ // Use it when you want to use JSON data from untrusted source as the email.
152
+ // If an attachment or message node tries to fetch something from a file the sending returns an error
153
+ ////disableFileAccess: ,
154
+ // disableUrlAccess – if true, then does not allow to use Urls as content
155
+ // ** disableUrlAccess: ,
156
+ //
157
+ // Pooling options
158
+ //
159
+ // pool – see Pooled SMTP for details about connection pooling : https://nodemailer.com/smtp/pooled/
160
+ //
161
+ // Proxy options
162
+ //
163
+ // proxy – all SMTP based transports allow to use proxies for making TCP connections to servers.
164
+ // Read about proxy support in Nodemailer from here: https://nodemailer.com/smtp/proxies/
165
+
166
+ /* TESTED */
167
+
168
+ /*
169
+ port: 465,
170
+ host: 'mail.afialapis.com',
171
+ auth: {
172
+ user: 'devel@afialapis.com',
173
+ pass: '***',
174
+ type: 'login',
175
+ },
176
+ secure: true,
177
+ tls: {
178
+ rejectUnauthorized: false
179
+ } ,
180
+ */
181
+
182
+ },
183
+ defaults: {
184
+ name: 'miolo',
185
+ from: 'miolo@afialapis.com',
186
+ to: 'devel@afialapis.com'
187
+ }
188
+ },
189
+ auth: {//basic: {
190
+ // auth_user: async (username, password) => { return {id: 1} },
191
+ // realm: '',
192
+ // paths: [],
193
+ //},
194
+ //passport: {
195
+ // get_user_id: (user, done) => done(null, user.id), // default
196
+ // find_user_by_id: (id, done) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
197
+ // local_auth_user: (username, password, done) => done(null, {id: 1})
198
+ // // auth=> done(null, user) noauth=> done(null, false, {message: ''}) err=> done(error, null)
199
+ // url_login: '/login',
200
+ // url_login: '/login',
201
+ // url_login: '/login',
202
+ //}
203
+ }
204
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.init_config = init_config;
7
+
8
+ var merge = require('assign-deep');
9
+
10
+ var base_config = require("./defaults.js");
11
+
12
+ function init_config(config) {
13
+ return merge(base_config, config);
14
+ }
package/lib/db/conn.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.init_db_connection = init_db_connection;
7
+
8
+ var {
9
+ getConnection
10
+ } = require('calustra-conn');
11
+
12
+ function init_db_connection(config) {
13
+ var conn = getConnection(config.connection, config.options);
14
+ return conn;
15
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.init_emailer = init_emailer;
7
+
8
+ var nodemailer = require('nodemailer');
9
+
10
+ function init_emailer(options, defaults) {
11
+ var silent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
12
+ var nmailer = nodemailer.createTransport(options, defaults);
13
+
14
+ function send_email(mail, cb) {
15
+ if (process.env.NODE_ENV != 'production') {
16
+ console.info('*********************************');
17
+ console.info('This mail would be sent if you were in production:');
18
+ console.info(mail);
19
+ console.info('*********************************');
20
+ } else if (silent) {
21
+ console.info('*********************************');
22
+ console.info('This mail will not be send (emailing is disabled):');
23
+ console.info(mail);
24
+ console.info('*********************************');
25
+ } else {
26
+ if (!cb) {
27
+ cb = function cb(err, info) {
28
+ if (err) {
29
+ console.error('NodeMailer error:');
30
+ console.error(err);
31
+ }
32
+
33
+ if (info) {
34
+ console.log('NodeMailer sent mail:');
35
+ console.log(info);
36
+ }
37
+ };
38
+ }
39
+
40
+ nmailer.sendMail(mail, cb);
41
+ }
42
+ }
43
+
44
+ function verify_emailer() {
45
+ console.info('[miolo][Verify][MAILER] Verifying...'); // verify connection configuration
46
+
47
+ nmailer.verify(function (error, _success) {
48
+ if (error) {
49
+ console.error('[miolo][Verify][MAILER] Verifying ERROR');
50
+ console.error(error);
51
+ } else {
52
+ console.info('[miolo][Verify][MAILER] Verifyed OK: Server is ready to take our messages'); //test_eail()
53
+ }
54
+ });
55
+ }
56
+
57
+ var emailer = {
58
+ send: send_email,
59
+ verify: verify_emailer
60
+ };
61
+ return emailer;
62
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.veryfy_emailer = veryfy_emailer;
7
+
8
+ var _index = require("./index");
9
+
10
+ function veryfy_emailer(config) {
11
+ var emailer = (0, _index.make_emailer)(config);
12
+ return emailer.verify();
13
+ }
package/lib/index.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "getDb", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _calustraRouter.getDb;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getModel", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _calustraRouter.getModel;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "init_cacher", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _cacher.init_cacher;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "init_db_connection", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _conn.init_db_connection;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "init_emailer", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _emailer.init_emailer;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "init_logger", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _logger.init_logger;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "miolo", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _server.miolo;
46
+ }
47
+ });
48
+
49
+ var _server = require("./server");
50
+
51
+ var _emailer = require("./emailer");
52
+
53
+ var _cacher = require("./cacher");
54
+
55
+ var _logger = require("./logger");
56
+
57
+ var _conn = require("./db/conn");
58
+
59
+ var _calustraRouter = require("calustra-router");
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _farrapaColors = require("farrapa-colors");
4
+
5
+ /* https://github.com/winstonjs/winston/issues/925 */
6
+
7
+ /* https://github.com/winstonjs/winston/issues/287 */
8
+ var {
9
+ createLogger,
10
+ format,
11
+ transports
12
+ } = require('winston');
13
+
14
+ var {
15
+ combine,
16
+ timestamp,
17
+ _label,
18
+ printf
19
+ } = format;
20
+
21
+ var init_logger = (config, emailer) => {
22
+ var LEVEL_COLORS = {
23
+ silly: _farrapaColors.LIGHT_CYAN,
24
+ debug: _farrapaColors.LIGHT_BLUE,
25
+ verbose: _farrapaColors.LIGHT_GREEN,
26
+ info: _farrapaColors.YELLOW,
27
+ warn: _farrapaColors.LIGHT_RED,
28
+ error: _farrapaColors.RED
29
+ };
30
+ var myFormat = printf(info => {
31
+ var _config$format;
32
+
33
+ var lc = LEVEL_COLORS[info.level];
34
+ var tm = new Date(info.timestamp);
35
+ var ts = tm.toLocaleString((config === null || config === void 0 ? void 0 : (_config$format = config.format) === null || _config$format === void 0 ? void 0 : _config$format.locale) || 'en'); //const ts= tm.toString().substr(4, 20)
36
+
37
+ return "[miolo] ".concat(lc(ts), " ").concat(lc(info.level), " ").concat(info.message);
38
+ });
39
+ var _log_transports = []; //
40
+ // Console transport
41
+ // If we're not in production then log to the `console` with the format:
42
+ // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
43
+ //
44
+
45
+ if (config.console.enabled) {
46
+ _log_transports.push(new transports.Console({
47
+ humanReadableUnhandledException: true,
48
+ level: config.console.level,
49
+ handleExceptions: true
50
+ }));
51
+ } //
52
+ // File transport
53
+ //
54
+
55
+
56
+ if (config.file.enabled) {
57
+ _log_transports.push(new transports.File({
58
+ filename: config.file.filename,
59
+ level: config.file.level,
60
+ humanReadableUnhandledException: true,
61
+ handleExceptions: true
62
+ }));
63
+ } //
64
+ // Mail transport
65
+ //
66
+
67
+
68
+ if (config.mail.enabled) {
69
+ var winston = require("winston");
70
+
71
+ var {
72
+ init_logger_to_mail
73
+ } = require("./logger_mail");
74
+
75
+ var MailerLogger = init_logger_to_mail(config.mail, emailer);
76
+ winston.transports.MailerLogger = MailerLogger;
77
+
78
+ _log_transports.push(new transports.MailerLogger({
79
+ level: config.mail.level,
80
+ humanReadableUnhandledException: true,
81
+ handleExceptions: true
82
+ }));
83
+ } //
84
+ // Logger
85
+ //
86
+
87
+
88
+ var logger = createLogger({
89
+ level: (config === null || config === void 0 ? void 0 : config.level) || 'silly',
90
+ format: combine(timestamp(), myFormat),
91
+ transports: _log_transports
92
+ });
93
+ return logger;
94
+ };
95
+
96
+ module.exports = {
97
+ init_logger
98
+ };