yakuza0 2.21.5 → 2.21.6-beta.0

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.
@@ -48,7 +48,7 @@ exports.default = function (config) {
48
48
  // '@nuxtjs/style-resources',
49
49
  // 'nuxt-polyfill',
50
50
  // ['nuxt-svg-sprite-loader', {symbolId: 'icon-[name]'}],
51
- _paths2.default.path.resolve(__dirname, './md.js'), _paths2.default.path.resolve(__dirname, './tfs.js'), _paths2.default.path.resolve(__dirname, './services.js'), _paths2.default.path.resolve(__dirname, './storage.js'), _paths2.default.path.resolve(__dirname, './http.js'), _paths2.default.path.resolve(__dirname, './ws.js'), _paths2.default.path.resolve(__dirname, './console.js'), _paths2.default.path.resolve(__dirname, './init.js'), _paths2.default.path.resolve(__dirname, './redirect.js'), _paths2.default.path.resolve(__dirname, './utils.js'), _paths2.default.path.resolve(__dirname, './yk.js'), _paths2.default.path.resolve(__dirname, './first.js')]);
51
+ _paths2.default.path.resolve(__dirname, './md.js'), _paths2.default.path.resolve(__dirname, './tfs.js'), _paths2.default.path.resolve(__dirname, './services.js'), _paths2.default.path.resolve(__dirname, './storage.js'), _paths2.default.path.resolve(__dirname, './log.js'), _paths2.default.path.resolve(__dirname, './ws.js'), _paths2.default.path.resolve(__dirname, './http.js'), _paths2.default.path.resolve(__dirname, './console.js'), _paths2.default.path.resolve(__dirname, './init.js'), _paths2.default.path.resolve(__dirname, './redirect.js'), _paths2.default.path.resolve(__dirname, './utils.js'), _paths2.default.path.resolve(__dirname, './yk.js'), _paths2.default.path.resolve(__dirname, './first.js')]);
52
52
 
53
53
  // if (yConf.pkg.yk.nuxt.mds.svg) {
54
54
  // mds.push(['nuxt-svg-sprite-loader', {symbolId: 'icon-[name]'}]);
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ exports.default = function (moduleOptions) {
8
+ this.addPlugin({
9
+ src: _paths2.default.ykTemplate + 'log.plugin.js'
10
+ });
11
+ };
12
+
13
+ var _paths = require('../../config/paths');
14
+
15
+ var _paths2 = _interopRequireDefault(_paths);
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+
19
+ module.exports = exports['default'];
@@ -5,14 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
 
7
7
  exports.default = function (moduleOptions) {
8
- var appConf = this.options.appConf;
8
+ this.addPlugin({
9
+ src: _paths2.default.ykTemplate + 'ws.plugin.js'
10
+ });
11
+ // const appConf = this.options.appConf;
9
12
 
10
- if (!appConf.standAlone) {
11
- this.addPlugin({
12
- src: _paths2.default.ykTemplate + 'ws.plugin.js',
13
- ssr: false
14
- });
15
- }
13
+ // if (!appConf.standAlone) {
14
+ // this.addPlugin({
15
+ // src: paths.ykTemplate + 'ws.plugin.js',
16
+ // ssr: false,
17
+ // })
18
+ // }
16
19
  };
17
20
 
18
21
  var _paths = require('../../config/paths');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yakuza0",
3
- "version": "2.21.5",
3
+ "version": "2.21.6-beta.0",
4
4
  "description": "yakuza0 with nuxt",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,71 @@
1
+ import yConf from 'yakuza0/config';
2
+ import {connect, req} from 'yakuza1/lib/ws';
3
+
4
+ export default async (ctx, inject) => {
5
+ const { $ws, $utils, $http, $yk } = ctx;
6
+ const event = {
7
+ debug: () => {
8
+ },
9
+ warn: () => {
10
+ },
11
+ error: () => {
12
+ },
13
+ };
14
+
15
+ const send = async (body) => {
16
+ if (!yConf.standAlone) {
17
+ if ($utils.checkServer()) {
18
+ try {
19
+ const result = await $http.post('$/feapiv1/log/publish', {
20
+ ...body,
21
+ }, {
22
+ hasHook: [],
23
+ })
24
+
25
+ return result && result.data
26
+ } catch (e) {
27
+ // console.log(e);
28
+ }
29
+ } else {
30
+ await connect();
31
+ await req('log/publish', {
32
+ body: {
33
+ ...body,
34
+ }
35
+ })
36
+ }
37
+ }
38
+ }
39
+
40
+ const msg = async ({head, detail, type}) => {
41
+ const body = {
42
+ head, detail, type,
43
+ sourceName: 'CLN框架日志 -> ' + yConf.name + (yConf.server.log.sourceName ? ' -> ' + yConf.server.log.sourceName : ''),
44
+ streamName: ' -> ' + $yk.appName + (yConf.server.log.streamName ? ' -> ' + yConf.server.log.streamName : ''),
45
+ }
46
+
47
+ if (yConf.server.log.level === type) {
48
+ if (yConf.server.log.onlySSR) {
49
+ if ($utils.checkServer()) {
50
+ await send(body)
51
+ }
52
+ } else {
53
+ await send(body)
54
+ }
55
+ }
56
+ }
57
+
58
+ event.debug = async (head, detail) => {
59
+ await msg({head, detail, type: 'debug'})
60
+ }
61
+ event.warn = async (head, detail) => {
62
+ await msg({head, detail, type: 'warn'})
63
+ }
64
+ event.error = async (head, detail) => {
65
+ await msg({head, detail, type: 'error'})
66
+ }
67
+
68
+ ctx.$log = event;
69
+ inject('log', event);
70
+ }
71
+
@@ -5,6 +5,7 @@ import {connect, req, decrypt} from 'yakuza1/lib/ws';
5
5
  import {mixin} from 'yakuza1/lib/encrypt';
6
6
 
7
7
  export default async (ctx, inject) => {
8
+ const { $http, $utils, $yk } = ctx;
8
9
  const event = {
9
10
  publish: () => {
10
11
  },
@@ -17,59 +18,76 @@ export default async (ctx, inject) => {
17
18
 
18
19
  const on = {};
19
20
 
20
- try {
21
- const client = await connect();
21
+ if (!yConf.standAlone) {
22
+ if ($utils.checkServer()) {
23
+ event.publish = async (topic, message) => {
24
+ try {
25
+ const result = await $http.post('$/feapiv1/mq/publish', {
26
+ topic,
27
+ message,
28
+ }, {
29
+ hasHook: [],
30
+ })
22
31
 
23
- event.on = (topic, callback) => {
24
- if (!_.isArray(on[topic])) {
25
- on[topic] = []
32
+ return result && result.data
33
+ } catch (e) {}
26
34
  }
27
- on[topic].push(callback);
28
- req('mq/subscribe', { body: { topic } });
29
- };
35
+ } else {
36
+ try {
37
+ const client = await connect();
30
38
 
31
- event.off = (topic) => {
32
- on[topic] = []
33
- req('mq/unsubscribe', { body: { topic } });
34
- };
39
+ event.on = (topic, callback) => {
40
+ if (!_.isArray(on[topic])) {
41
+ on[topic] = []
42
+ }
43
+ on[topic].push(callback);
44
+ req('mq/subscribe', { body: { topic } });
45
+ };
46
+
47
+ event.off = (topic) => {
48
+ on[topic] = []
49
+ req('mq/unsubscribe', { body: { topic } });
50
+ };
35
51
 
36
- event.publish = (topic, message) => {
37
- req('mq/publish', {
38
- body: {
39
- topic,
40
- message,
52
+ event.publish = (topic, message) => {
53
+ req('mq/publish', {
54
+ body: {
55
+ topic,
56
+ message,
57
+ }
58
+ })
41
59
  }
42
- })
43
- }
44
60
 
45
- event.history = async (topic, options = {}) => await req('mq/history', {
46
- body: {
47
- topic,
48
- options,
49
- }
50
- });
51
- client.on('mq/message', (res) => {
52
- const key = mixin.getKey(client.id);
53
- const { topic, message } = decrypt(res, key);
54
- if (_.isArray(on[topic])) {
55
- on[topic].forEach(callback => {
56
- if (typeof callback === 'function') {
57
- callback(message);
61
+ event.history = async (topic, options = {}) => await req('mq/history', {
62
+ body: {
63
+ topic,
64
+ options,
58
65
  }
59
- })
60
- }
61
- });
66
+ });
67
+ client.on('mq/message', (res) => {
68
+ const key = mixin.getKey(client.id);
69
+ const { topic, message } = decrypt(res, key);
70
+ if (_.isArray(on[topic])) {
71
+ on[topic].forEach(callback => {
72
+ if (typeof callback === 'function') {
73
+ callback(message);
74
+ }
75
+ })
76
+ }
77
+ });
62
78
 
63
- client.on('reconnect', (attemptNumber) => {
64
- if (_.isPlainObject(on)) {
65
- _.forEach(on, (arr, topic) => {
66
- if (typeof topic === 'string') {
67
- req('mq/subscribe', { body: { topic } });
79
+ client.on('reconnect', (attemptNumber) => {
80
+ if (_.isPlainObject(on)) {
81
+ _.forEach(on, (arr, topic) => {
82
+ if (typeof topic === 'string') {
83
+ req('mq/subscribe', { body: { topic } });
84
+ }
85
+ })
68
86
  }
69
- })
87
+ });
88
+ } catch (e) {
70
89
  }
71
- });
72
- } catch (e) {
90
+ }
73
91
  }
74
92
 
75
93
  ctx.$ws = event;
@@ -302,6 +302,12 @@ var render = function () {
302
302
  cookieSameSite: 'Lax',
303
303
  // ...mainConf.server,
304
304
  // ...ykConf.server,
305
+ log: {
306
+ onlySSR: true,
307
+ level: 'debug',
308
+ sourceName: '',
309
+ streamName: ''
310
+ },
305
311
  csp: {
306
312
  enabled: true,
307
313
  strict: false,
@@ -884,6 +890,7 @@ var render = function () {
884
890
 
885
891
  v.server = (0, _extends3.default)({}, conf.server, v.server, {
886
892
  f5Offline: checkBool(conf.server.f5Offline, v.server && v.server.f5Offline),
893
+ log: (0, _extends3.default)({}, conf.server.log, v.server && v.server.log),
887
894
  browsers: {
888
895
  redirect: (0, _extends3.default)({}, conf.server && conf.server.browsers && conf.server.browsers.redirect, v.server && v.server.browsers && v.server.browsers.redirect),
889
896
  static: v.server && v.server.browsers && v.server.browsers.static || conf.server && conf.server.browsers && conf.server.browsers.static