@mixd-id/web-scaffold 0.1.230406237 → 0.1.230406239

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mixd-id/web-scaffold",
3
3
  "private": false,
4
- "version": "0.1.230406237",
4
+ "version": "0.1.230406239",
5
5
  "scripts": {
6
6
  "dev": "vite serve",
7
7
  "build": "vite build",
@@ -11,8 +11,7 @@
11
11
  "exports": {
12
12
  ".": "./src/index.js",
13
13
  "./themes/default": "./src/themes/default/index.js",
14
- "./components/Modal.vue": "./src/components/Modal.vue",
15
- "./components/Textbox.vue": "./src/components/Textbox.vue",
14
+ "./components/*": "./src/components/*",
16
15
  "./mixin/component": "./src/mixin/component.js",
17
16
  "./mixin/edit-mode": "./src/mixin/edit-mode.js",
18
17
  "./middleware/http/trim-string": "./src/middleware/http/trim-string.js",
package/src/utils/wss.js CHANGED
@@ -136,7 +136,10 @@ class WSS extends EventEmitter2{
136
136
  socket.leave = (channel) => {
137
137
  if((socket.channels ?? {})[channel]){
138
138
  delete socket.channels[channel]
139
- //console.log('leave', channel)
139
+
140
+ if(this._opt.debug){
141
+ console.log('leave', channel)
142
+ }
140
143
  }
141
144
  }
142
145
 
@@ -146,7 +149,10 @@ class WSS extends EventEmitter2{
146
149
  }
147
150
 
148
151
  socket.channels[channel] = 1
149
- //console.log('join', channel)
152
+
153
+ if(this._opt.debug){
154
+ console.log('join', channel)
155
+ }
150
156
  }
151
157
 
152
158
  socket.to = (channel) => {
@@ -189,7 +195,13 @@ class WSS extends EventEmitter2{
189
195
  }
190
196
  catch(e){
191
197
  status = 500
192
- data = e
198
+ data = {
199
+ name: e.name,
200
+ message: e.message,
201
+ errors: e.errors,
202
+ stack: process.env.APP_DEBUG === 'true' ?
203
+ e.stack : undefined
204
+ }
193
205
  }
194
206
  break
195
207
  }
@@ -216,7 +228,10 @@ class WSS extends EventEmitter2{
216
228
  }
217
229
 
218
230
  async broadcast(channel, { model, event, items }){
219
- //console.log('broadcast', channel, JSON.stringify({ model, event, items }).substring(0, 70))
231
+
232
+ if(this._opt.debug){
233
+ console.log('broadcast', channel, JSON.stringify({ model, event, items }).substring(0, 70))
234
+ }
220
235
 
221
236
  for(let socket of this._instance.clients){
222
237
  if(socket.readyState === WebSocket.OPEN && (socket.channels ?? {})[channel]){
package/src/utils/wss.mjs CHANGED
@@ -1,6 +1,15 @@
1
1
  import CryptoJS from "crypto-js";
2
2
  import EventEmitter2 from "eventemitter2";
3
3
 
4
+ const fileToDataURL = (file) => {
5
+ return new Promise((resolve, reject) => {
6
+ const reader = new FileReader();
7
+ reader.onload = (event) => resolve(event.target.result);
8
+ reader.onerror = (error) => reject(error);
9
+ reader.readAsDataURL(file);
10
+ });
11
+ };
12
+
4
13
  class WSS extends EventEmitter2{
5
14
 
6
15
  _instance
@@ -12,93 +21,30 @@ class WSS extends EventEmitter2{
12
21
 
13
22
  static async convertDataUrlObj(obj){
14
23
 
15
- const fileToDataURL = (file) => {
16
- return new Promise((resolve, reject) => {
17
- const reader = new FileReader();
18
- reader.onload = (event) => resolve(event.target.result);
19
- reader.onerror = (error) => reject(error);
20
- reader.readAsDataURL(file);
21
- });
22
- };
23
-
24
- const processObjectProperties = async (inputObj) => {
25
- let outputObj;
26
-
27
- if(Array.isArray(inputObj)){
28
- outputObj = []
29
- for(let i = 0; i < inputObj.length; i++){
30
- const value = inputObj[i];
31
-
32
- if (value instanceof File) {
33
- outputObj[i] = await fileToDataURL(value);
34
- } else if (typeof value === 'object' && value !== null) {
35
- outputObj[i] = await processObjectProperties(value);
36
- } else {
37
- outputObj[i] = value;
38
- }
39
- }
40
- }
41
- else{
42
- outputObj = {}
43
-
44
- for (const key in inputObj) {
45
- if (inputObj.hasOwnProperty(key)) {
46
- const value = inputObj[key];
47
-
48
- if (value instanceof File) {
49
- outputObj[key] = await fileToDataURL(value);
50
- } else if (typeof value === 'object' && value !== null) {
51
- outputObj[key] = await processObjectProperties(value);
52
- } else {
53
- outputObj[key] = value;
54
- }
55
- }
56
- }
57
- }
58
-
59
-
60
- return outputObj;
61
- };
62
-
63
- return processObjectProperties(obj);
64
- }
65
-
66
- static async revertDataUrlObj(obj){
67
-
68
- const processObjectProperties = async (inputObj) => {
69
- let outputObj;
70
-
71
- if(Array.isArray(inputObj)){
72
- outputObj = []
73
- for (let i = 0; i < inputObj.length; i++) {
74
- let value = inputObj[i];
24
+ let output
75
25
 
76
- if (typeof value === 'object' && value !== null) {
77
- outputObj[i] = await processObjectProperties(value);
78
- } else {
79
- outputObj[i] = value;
80
- }
81
- }
26
+ if(Array.isArray(obj)){
27
+ output = []
28
+ for(let i = 0; i < obj.length; i++){
29
+ output.push(await WSS.convertDataUrlObj(obj[i]));
82
30
  }
83
- else if(typeof inputObj === 'object' && inputObj !== null){
84
- outputObj = {}
85
- for (const key in inputObj) {
86
- if (inputObj.hasOwnProperty(key)) {
87
- let value = inputObj[key];
88
-
89
- if (typeof value === 'object' && value !== null) {
90
- outputObj[key] = await processObjectProperties(value);
91
- } else {
92
- outputObj[key] = value;
93
- }
94
- }
31
+ }
32
+ else if(obj instanceof File || obj instanceof Blob) {
33
+ output = await fileToDataURL(obj);
34
+ }
35
+ else if(typeof obj === 'object' && obj !== null){
36
+ output = {}
37
+ for (const key in obj) {
38
+ if (obj.hasOwnProperty(key)) {
39
+ output[key] = await WSS.convertDataUrlObj(obj[key])
95
40
  }
96
41
  }
42
+ }
43
+ else{
44
+ output = obj;
45
+ }
97
46
 
98
- return outputObj;
99
- };
100
-
101
- return processObjectProperties(obj);
47
+ return output
102
48
  }
103
49
 
104
50
  constructor(opt) {
@@ -130,7 +76,7 @@ class WSS extends EventEmitter2{
130
76
  }
131
77
 
132
78
  _onFocus = () => {
133
- this.emit('focus')
79
+ this.emit('window', 'focus', [])
134
80
 
135
81
  if(this._lastBlurAt){
136
82
  this.send('ping', {}, { timeout:1000 })
@@ -142,10 +88,10 @@ class WSS extends EventEmitter2{
142
88
 
143
89
  _onOnlineChanged = (e) => {
144
90
  if(!navigator.onLine){
145
- this.emit('disconnect', e)
91
+ this.emit('disconnect', e, [])
146
92
  }
147
93
  else{
148
- this.emit('connect')
94
+ this.emit('connect', null, [])
149
95
  }
150
96
  }
151
97
 
@@ -153,8 +99,7 @@ class WSS extends EventEmitter2{
153
99
  const secretKey = this._opt.key;
154
100
  const encryptedString = new TextDecoder().decode(binaryData)
155
101
  const decryptedData = CryptoJS.AES.decrypt(encryptedString, secretKey).toString(CryptoJS.enc.Utf8);
156
- const receivedObject = JSON.parse(decryptedData);
157
- return await WSS.revertDataUrlObj(receivedObject);
102
+ return JSON.parse(decryptedData)
158
103
  }
159
104
 
160
105
  async toBinaryData(obj){
@@ -172,7 +117,7 @@ class WSS extends EventEmitter2{
172
117
  this._instance.onopen = () => {
173
118
  this.send('_auth', this._opt.auth)
174
119
  .then(() => {
175
- reconnect ? this.emit('reconnect') : this.emit('connect')
120
+ reconnect ? this.emit('reconnect', null, []) : this.emit('connect', null, [])
176
121
 
177
122
  for(let sendParams of this._pendingSend){
178
123
  this.sendSync(sendParams.path, sendParams.params, sendParams.cb, sendParams.err)
@@ -192,20 +137,24 @@ class WSS extends EventEmitter2{
192
137
  status === 200 ? cb(data) : err(data)
193
138
  delete this._callbacks[_requestId]
194
139
 
195
- this.emit('debug', 'fn', [ [ new Date().getTime() - t1, path, params, data ] ])
140
+ if(this._opt.debug){
141
+ console.log(new Date().getTime() - t1, path, params, data)
142
+ }
196
143
  }
197
144
  }
198
145
  else{
199
146
  const { model, event, items } = data
200
147
  this.emit(model, event, items)
201
148
 
202
- this.emit('debug', 'signal', [ [ model, event, items ] ])
149
+ if(this._opt.debug){
150
+ console.log('SIGNAL', model, event, items)
151
+ }
203
152
  }
204
153
 
205
154
  };
206
155
 
207
156
  this._instance.onerror = (e) => {
208
- this.emit('error', e)
157
+ this.emit('error', e, [])
209
158
  }
210
159
 
211
160
  this._instance.onclose = (e) => {
@@ -213,11 +162,11 @@ class WSS extends EventEmitter2{
213
162
  switch(e.code){
214
163
 
215
164
  case 1002:
216
- this.emit('connect_error', e)
165
+ this.emit('connect_error', e, [])
217
166
  break
218
167
 
219
168
  default:
220
- this.emit('disconnect')
169
+ this.emit('disconnect', null, [])
221
170
  break
222
171
  }
223
172
  };